Skip to content

Commit 18b0eff

Browse files
authored
fix: Add --yes and --use-previous-options to config-ssh (#2458)
1 parent 7cce7a9 commit 18b0eff

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

cli/configssh.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func configSSH() *cobra.Command {
138138
var (
139139
sshConfigFile string
140140
sshConfigOpts sshConfigOptions
141+
usePreviousOpts bool
141142
coderConfigFile string
142143
showDiff bool
143144
skipProxyCommand bool
@@ -218,7 +219,9 @@ func configSSH() *cobra.Command {
218219

219220
// Avoid prompting in diff mode (unexpected behavior)
220221
// or when a previous config does not exist.
221-
if !showDiff && lastConfig != nil && !sshConfigOpts.equal(*lastConfig) {
222+
if usePreviousOpts && lastConfig != nil {
223+
sshConfigOpts = *lastConfig
224+
} else if !showDiff && lastConfig != nil && !sshConfigOpts.equal(*lastConfig) {
222225
newOpts := sshConfigOpts.asList()
223226
newOptsMsg := "\n\n New options: none"
224227
if len(newOpts) > 0 {
@@ -394,11 +397,14 @@ func configSSH() *cobra.Command {
394397
cmd.Flags().BoolVarP(&showDiff, "diff", "D", false, "Show diff of changes that will be made.")
395398
cmd.Flags().BoolVarP(&skipProxyCommand, "skip-proxy-command", "", false, "Specifies whether the ProxyCommand option should be skipped. Useful for testing.")
396399
_ = cmd.Flags().MarkHidden("skip-proxy-command")
400+
cliflag.BoolVarP(cmd.Flags(), &usePreviousOpts, "use-previous-options", "", "CODER_SSH_USE_PREVIOUS_OPTIONS", false, "Specifies whether or not to keep options from previous run of config-ssh.")
397401

398402
// Deprecated: Remove after migration period.
399403
cmd.Flags().StringVar(&coderConfigFile, "test.ssh-coder-config-file", sshDefaultCoderConfigFileName, "Specifies the path to an Coder SSH config file. Useful for testing.")
400404
_ = cmd.Flags().MarkHidden("test.ssh-coder-config-file")
401405

406+
cliui.AllowSkipPrompt(cmd)
407+
402408
return cmd
403409
}
404410

cli/configssh_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,54 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
446446
{match: "Continue?", write: "no"},
447447
},
448448
},
449+
{
450+
name: "Do not prompt when using --yes",
451+
writeConfig: writeConfig{
452+
ssh: strings.Join([]string{
453+
headerStart,
454+
"# Last config-ssh options:",
455+
"# :ssh-option=ForwardAgent=yes",
456+
"#",
457+
headerEnd,
458+
"",
459+
}, "\n"),
460+
},
461+
wantConfig: wantConfig{
462+
ssh: strings.Join([]string{
463+
// Last options overwritten.
464+
baseHeader,
465+
"",
466+
}, "\n"),
467+
},
468+
args: []string{"--yes"},
469+
},
470+
{
471+
name: "Do not prompt for new options when prev opts flag is set",
472+
writeConfig: writeConfig{
473+
ssh: strings.Join([]string{
474+
headerStart,
475+
"# Last config-ssh options:",
476+
"# :ssh-option=ForwardAgent=yes",
477+
"#",
478+
headerEnd,
479+
"",
480+
}, "\n"),
481+
},
482+
wantConfig: wantConfig{
483+
ssh: strings.Join([]string{
484+
headerStart,
485+
"# Last config-ssh options:",
486+
"# :ssh-option=ForwardAgent=yes",
487+
"#",
488+
headerEnd,
489+
"",
490+
}, "\n"),
491+
},
492+
args: []string{
493+
"--use-previous-options",
494+
"--yes",
495+
},
496+
},
449497

450498
// Tests for deprecated split coder config.
451499
{

0 commit comments

Comments
 (0)