Skip to content

Commit 9d64680

Browse files
committed
feat: Update options prompt, default to using new options
1 parent 000c9b4 commit 9d64680

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
@@ -174,19 +174,29 @@ func configSSH() *cobra.Command {
174174
}
175175
lastCoderConfig := sshCoderConfigParseLastOptions(bytes.NewReader(coderConfigRaw), coderConfig.sshConfigDefaultFile)
176176

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

0 commit comments

Comments
 (0)