Skip to content

Commit 3ec4163

Browse files
committed
fix: Do not prompt for previous opts on first run
1 parent f11b5b1 commit 3ec4163

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cli/configssh.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ func configSSH() *cobra.Command {
171171
return xerrors.Errorf("read ssh config failed: %w", err)
172172
}
173173

174+
coderConfigExists := true
174175
coderConfigRaw, err := os.ReadFile(coderConfigFile)
175-
if err != nil && !errors.Is(err, fs.ErrNotExist) {
176-
return xerrors.Errorf("read ssh config failed: %w", err)
176+
if err != nil {
177+
if errors.Is(err, fs.ErrNotExist) {
178+
coderConfigExists = false
179+
} else {
180+
return xerrors.Errorf("read ssh config failed: %w", err)
181+
}
177182
}
178183
if len(coderConfigRaw) > 0 {
179184
if !bytes.HasPrefix(coderConfigRaw, []byte(sshCoderConfigHeader)) {
@@ -182,8 +187,9 @@ func configSSH() *cobra.Command {
182187
}
183188
lastCoderConfig := sshCoderConfigParseLastOptions(bytes.NewReader(coderConfigRaw), coderConfig.sshConfigDefaultFile)
184189

185-
// Avoid prompting in diff mode (unexpected behavior).
186-
if !showDiff && !coderConfig.equal(lastCoderConfig) {
190+
// Avoid prompting in diff mode (unexpected behavior)
191+
// or when a previous config does not exist.
192+
if !showDiff && !coderConfig.equal(lastCoderConfig) && coderConfigExists {
187193
newOpts := coderConfig.asList()
188194
newOptsMsg := "\n\n New options: none"
189195
if len(newOpts) > 0 {

0 commit comments

Comments
 (0)