feat: Refactor CLI config-ssh to improve UX (#1900)

- Magic block is replaced by Include statement
- Writes are only done on changes
- Inform user of changes via prompt
- Allow displaying changes via `--diff`
- Remove magic block if present
- Safer config writing via tmp-file + rename
- Parse previous `config-ssh` options, compare to new options and ask to use new (otherwise old ones are used)
- Tests the new functionality

Fixes #1326
This commit is contained in:
Mathias Fredriksson
2022-06-08 11:45:29 +03:00
committed by GitHub
parent 945fa9dacf
commit b65259f95e
5 changed files with 943 additions and 97 deletions

View File

@ -244,6 +244,24 @@ func isTTY(cmd *cobra.Command) bool {
return isatty.IsTerminal(file.Fd())
}
// isTTYOut returns whether the passed reader is a TTY or not.
// This accepts a reader to work with Cobra's "OutOrStdout"
// function for simple testing.
func isTTYOut(cmd *cobra.Command) bool {
// If the `--force-tty` command is available, and set,
// assume we're in a tty. This is primarily for cases on Windows
// where we may not be able to reliably detect this automatically (ie, tests)
forceTty, err := cmd.Flags().GetBool(varForceTty)
if forceTty && err == nil {
return true
}
file, ok := cmd.OutOrStdout().(*os.File)
if !ok {
return false
}
return isatty.IsTerminal(file.Fd())
}
func usageTemplate() string {
// usageHeader is defined in init().
return `{{usageHeader "Usage:"}}