Skip to content

Commit f849df0

Browse files
committed
feat: Update options prompt, default to using new options
1 parent 9b44ab0 commit f849df0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

cli/configssh.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,29 @@ func configSSH() *cobra.Command {
176176
}
177177
lastCoderConfig := sshCoderConfigParseLastOptions(bytes.NewReader(coderConfigRaw), coderConfig.sshConfigDefaultFile)
178178

179-
// Only prompt when no arguments are provided and avoid
180-
// prompting in diff mode (unexpected behavior).
181-
if !showDiff && coderConfig.isZero() && !lastCoderConfig.isZero() {
179+
// Avoid prompting in diff mode (unexpected behavior).
180+
if !showDiff && !coderConfig.equal(lastCoderConfig) {
181+
newOpts := coderConfig.asList()
182+
newOptsMsg := "\n\n New options: none"
183+
if len(newOpts) > 0 {
184+
newOptsMsg = fmt.Sprintf("\n\n New options:\n * %s", strings.Join(newOpts, "\n * "))
185+
}
186+
oldOpts := lastCoderConfig.asList()
187+
oldOptsMsg := "\n\n Previouss options: none"
188+
if len(oldOpts) > 0 {
189+
oldOptsMsg = fmt.Sprintf("\n\n Previous options:\n * %s", strings.Join(oldOpts, "\n * "))
190+
}
191+
182192
line, err := cliui.Prompt(cmd, cliui.PromptOptions{
183-
Text: fmt.Sprintf("Found previous configuration option(s):\n\n - %s\n\n Use previous option(s)?", strings.Join(lastCoderConfig.asList(), "\n - ")),
193+
Text: fmt.Sprintf("New options differ from previous options:%s%s\n\n Use new options?", newOptsMsg, oldOptsMsg),
184194
IsConfirm: true,
185195
})
186196
if err != nil {
187197
// TODO(mafredri): Better way to differ between "no" and Ctrl+C?
188198
if line == "" && xerrors.Is(err, cliui.Canceled) {
189199
return nil
190200
}
191-
} else {
201+
// Selecting "no" will use the last config.
192202
coderConfig = lastCoderConfig
193203
}
194204
_, _ = fmt.Fprint(out, "\n")

0 commit comments

Comments
 (0)