diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/cli/interface.go | 40 | ||||
| -rw-r--r-- | internal/cli/query.go | 18 | ||||
| -rw-r--r-- | internal/prompt/cloud.go | 2 | ||||
| -rw-r--r-- | internal/prompt/main.go | 18 | ||||
| -rw-r--r-- | internal/rtree/index.go | 2 | ||||
| -rw-r--r-- | internal/rtree/shared_test.go | 3 |
6 files changed, 42 insertions, 41 deletions
diff --git a/internal/cli/interface.go b/internal/cli/interface.go index a88212b..5e41894 100644 --- a/internal/cli/interface.go +++ b/internal/cli/interface.go @@ -27,18 +27,18 @@ import ( "sort" "strings" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) -//Interface wraps access to the CLI, including input, output and subprocesses. +// Interface wraps access to the CLI, including input, output and subprocesses. var Interface *Implementation func init() { SetupInterface(os.Stdin, os.Stdout, os.Stderr, DefaultCommandRunner) } -//SetupInterface prepares the Interface instance with nonstandard file streams -//or a nonstandard CommandRunner. This is only required for unit tests. +// SetupInterface prepares the Interface instance with nonstandard file streams +// or a nonstandard CommandRunner. This is only required for unit tests. func SetupInterface(stdin io.Reader, stdout, stderr io.Writer, commandRunner CommandRunner) { Interface = &Implementation{ stdin: stdin, @@ -48,14 +48,14 @@ func SetupInterface(stdin io.Reader, stdout, stderr io.Writer, commandRunner Com commandRunner: commandRunner, } - if stdinFile, ok := stdin.(*os.File); ok && terminal.IsTerminal(int(stdinFile.Fd())) { + if stdinFile, ok := stdin.(*os.File); ok && term.IsTerminal(int(stdinFile.Fd())) { Interface.tui = &terminalTUI{Interface} } else { Interface.tui = &pipeTUI{Interface} } } -//Implementation wraps access to the CLI, including input, output and subprocesses. +// Implementation wraps access to the CLI, including input, output and subprocesses. type Implementation struct { stdin io.Reader stdout io.Writer @@ -72,8 +72,8 @@ type Implementation struct { StdoutProtected bool } -//TUI provides the interactive parts of the cli.Implementation, so that these can be -//easily swapped out for mock implementations in unit tests. +// TUI provides the interactive parts of the cli.Implementation, so that these can be +// easily swapped out for mock implementations in unit tests. type TUI interface { //ReadLine reads a line from stdin (if tty: uses canonical mode). ReadLine(prompt string) (string, error) @@ -98,18 +98,18 @@ func (i *Implementation) safeStdout() io.Writer { //////////////////////////////////////////////////////////////////////////////// // input -//ReadLine reads a line from stdin (if tty: uses canonical mode). +// ReadLine reads a line from stdin (if tty: uses canonical mode). func (i *Implementation) ReadLine(prompt string) (string, error) { return i.tui.ReadLine(prompt) } -//Confirm displays a yes/no question and returns whether the user answered "yes". +// Confirm displays a yes/no question and returns whether the user answered "yes". func (i *Implementation) Confirm(question string) (bool, error) { return i.tui.Confirm(question) } -//Query displays a question and a set of answers and allows the user to select -//one of the answers. Returns the Return attribute of the selected Choice. +// Query displays a question and a set of answers and allows the user to select +// one of the answers. Returns the Return attribute of the selected Choice. func (i *Implementation) Query(prompt string, choices ...Choice) (string, error) { return i.tui.Query(prompt, choices...) } @@ -117,12 +117,12 @@ func (i *Implementation) Query(prompt string, choices ...Choice) (string, error) //////////////////////////////////////////////////////////////////////////////// // subprocesses -//Run executes the given command on the same stdout and stderr. +// Run executes the given command on the same stdout and stderr. func (i *Implementation) Run(c Command) error { return i.commandRunner(c, nil, i.safeStdout(), i.stderr) } -//CaptureStdout executes the given command on the same stderr and captures its stdout. +// CaptureStdout executes the given command on the same stderr and captures its stdout. func (i *Implementation) CaptureStdout(c Command) (string, error) { var buf bytes.Buffer err := i.commandRunner(c, nil, &buf, i.stderr) @@ -132,13 +132,13 @@ func (i *Implementation) CaptureStdout(c Command) (string, error) { //////////////////////////////////////////////////////////////////////////////// // output -//ShowResult displays the result of a computation on stdout. +// ShowResult displays the result of a computation on stdout. func (i *Implementation) ShowResult(str string) { str = strings.TrimSpace(str) + "\n" i.stdout.Write([]byte(str)) } -//ShowResultsSorted calls ShowResult() on each of the results after sorting them. +// ShowResultsSorted calls ShowResult() on each of the results after sorting them. func (i *Implementation) ShowResultsSorted(strs []string) { sort.Strings(strs) for _, str := range strs { @@ -146,22 +146,22 @@ func (i *Implementation) ShowResultsSorted(strs []string) { } } -//ShowProgress displays a progress message on stderr. +// ShowProgress displays a progress message on stderr. func (i *Implementation) ShowProgress(str string) { i.tui.Print(i.stderr, fmt.Sprintf("\x1B[0;1;36m>>\x1B[0;36m %s\x1B[0m\n", strings.TrimSpace(str))) } -//ShowWarning displays a warning message on stderr. +// ShowWarning displays a warning message on stderr. func (i *Implementation) ShowWarning(str string) { i.tui.Print(i.stderr, fmt.Sprintf("\x1B[0;1;33m!!\x1B[0;33m %s\x1B[0m\n", strings.TrimSpace(str))) } -//ShowError displays an error message on stderr. +// ShowError displays an error message on stderr. func (i *Implementation) ShowError(str string) { i.tui.Print(i.stderr, fmt.Sprintf("\x1B[0;1;31m!!\x1B[0;31m %s\x1B[0m\n", strings.TrimSpace(str))) } -//ShowUsage displays a usage synopsis on stderr. +// ShowUsage displays a usage synopsis on stderr. func (i *Implementation) ShowUsage(str string) { str = strings.TrimSpace(str) + "\n" i.stderr.Write([]byte(str)) diff --git a/internal/cli/query.go b/internal/cli/query.go index add170c..a2bd004 100644 --- a/internal/cli/query.go +++ b/internal/cli/query.go @@ -26,11 +26,11 @@ import ( "strconv" "strings" - terminal "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) -//cannot use `var errInterrupted = errors.New("Interrupted!")` because golint -//complains about the formatting of the error message +// cannot use `var errInterrupted = errors.New("Interrupted!")` because golint +// complains about the formatting of the error message type errInterrupted struct{} func (e errInterrupted) Error() string { @@ -75,7 +75,7 @@ func (t terminalTUI) Confirm(question string) (bool, error) { } } -//Choice is a thing that the user can choose during Query(). +// Choice is a thing that the user can choose during Query(). type Choice struct { //If given, the choice can be selected by pressing the key that //produces this character. @@ -212,11 +212,11 @@ func (b *buffer) getNextInput() []byte { return result } - oldState, err := terminal.MakeRaw(0) + oldState, err := term.MakeRaw(0) if err != nil { panic(err) } - defer terminal.Restore(0, oldState) + defer term.Restore(0, oldState) //fill buffer some more n, err := b.Input.Read(b.buf[b.fill:]) @@ -235,7 +235,7 @@ type pipeTUI struct { i *Implementation } -//AnsiColorCodeRx is a regexp that matches ANSI escape sequences of the type SGR. +// AnsiColorCodeRx is a regexp that matches ANSI escape sequences of the type SGR. var AnsiColorCodeRx = regexp.MustCompile("\x1B" + `\[[0-9;]*m`) func (t *pipeTUI) Print(w io.Writer, msg string) { @@ -267,8 +267,8 @@ func (t *pipeTUI) Confirm(question string) (bool, error) { return ok, nil } -//Query for the pipe TUI is limited to exact matches of the choice text, or -//matching by choice shortcut. +// Query for the pipe TUI is limited to exact matches of the choice text, or +// matching by choice shortcut. func (t *pipeTUI) Query(prompt string, choices ...Choice) (string, error) { str, err := t.i.stdinBuf.ReadString('\n') if err != nil { diff --git a/internal/prompt/cloud.go b/internal/prompt/cloud.go index 0f69243..624f56d 100644 --- a/internal/prompt/cloud.go +++ b/internal/prompt/cloud.go @@ -24,7 +24,7 @@ import ( "path/filepath" "strings" - yaml "gopkg.in/yaml.v2" + yaml "go.yaml.in/yaml/v3" ) func getKubernetesField() string { diff --git a/internal/prompt/main.go b/internal/prompt/main.go index f403f6c..84d258c 100644 --- a/internal/prompt/main.go +++ b/internal/prompt/main.go @@ -23,13 +23,13 @@ import ( "os" "strings" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" "github.com/majewsky/gofu/internal/cli" ) -//Exec executes the prettyprompt applet and returns an exit code (0 for -//success, >0 for error). +// Exec executes the prettyprompt applet and returns an exit code (0 for +// success, >0 for error). func Exec(args []string) int { var tt TerminalTitle fields := []string{ @@ -55,7 +55,7 @@ func Exec(args []string) int { lineWidth := getPrintableLength(line) //add dashes to expand `line` to fill the terminal's width - termWidth, _, err := terminal.GetSize(0) + termWidth, _, err := term.GetSize(0) if err != nil { termWidth = 80 } @@ -111,10 +111,10 @@ func getPrintableLength(text string) int { return len(cli.AnsiColorCodeRx.ReplaceAllString(text, "")) } -//withColor adds ANSI escape sequences to the string to display it with a -//certain color. The color is given as the semicolon-separated list of -//arguments to the ANSI escape sequence SGR, e.g. "1;41" for bold with red -//background. +// withColor adds ANSI escape sequences to the string to display it with a +// certain color. The color is given as the semicolon-separated list of +// arguments to the ANSI escape sequence SGR, e.g. "1;41" for bold with red +// background. func withColor(color, text string) string { if color == "0" { return text @@ -122,7 +122,7 @@ func withColor(color, text string) string { return fmt.Sprintf("\x1B[%sm%s\x1B[0m", color, text) } -//withType adds a type annotation with a standardized format to the text. +// withType adds a type annotation with a standardized format to the text. func withType(typeStr, text string) string { return fmt.Sprintf("\x1B[37m%s:\x1B[0m%s", typeStr, text) } diff --git a/internal/rtree/index.go b/internal/rtree/index.go index 201d4f9..09ababa 100644 --- a/internal/rtree/index.go +++ b/internal/rtree/index.go @@ -29,7 +29,7 @@ import ( "github.com/majewsky/gofu/internal/cli" - yaml "gopkg.in/yaml.v2" + yaml "go.yaml.in/yaml/v3" ) // Index represents the contents of the index file. diff --git a/internal/rtree/shared_test.go b/internal/rtree/shared_test.go index 3bfdaba..e26eb11 100644 --- a/internal/rtree/shared_test.go +++ b/internal/rtree/shared_test.go @@ -29,8 +29,9 @@ import ( "strings" "testing" + yaml "go.yaml.in/yaml/v3" + "github.com/majewsky/gofu/internal/cli" - yaml "gopkg.in/yaml.v2" ) // Path to a directory where tests can put their index files. |
