Skip to content

Commit bd72606

Browse files
committed
fix: ESC exits picker cleanly in edit and push commands
Pressing ESC in any interactive selector (openboot edit config picker, openboot push config picker or create-new prompts) now exits silently with 'Cancelled.' instead of printing an error.
1 parent a7f8520 commit bd72606

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

internal/cli/edit.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package cli
22

33
import (
4+
"errors"
45
"fmt"
56
"os/exec"
67

8+
"github.com/charmbracelet/huh"
79
"github.com/openbootdotdev/openboot/internal/auth"
810
"github.com/openbootdotdev/openboot/internal/ui"
911
"github.com/spf13/cobra"
@@ -88,6 +90,9 @@ func pickConfig(token, apiBase string) (string, error) {
8890
fmt.Println()
8991
choice, err := ui.SelectOption("Which config would you like to edit?", options)
9092
if err != nil {
93+
if errors.Is(err, huh.ErrUserAborted) {
94+
return "", nil
95+
}
9196
return "", fmt.Errorf("select config: %w", err)
9297
}
9398

internal/cli/push.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/charmbracelet/huh"
1516
"github.com/openbootdotdev/openboot/internal/auth"
1617
"github.com/openbootdotdev/openboot/internal/config"
1718
"github.com/openbootdotdev/openboot/internal/httputil"
@@ -45,10 +46,17 @@ Use --slug to target a specific existing config.`,
4546
RunE: func(cmd *cobra.Command, args []string) error {
4647
slug, _ := cmd.Flags().GetString("slug")
4748
message, _ := cmd.Flags().GetString("message")
49+
var err error
4850
if len(args) == 0 {
49-
return runPushAuto(slug, message)
51+
err = runPushAuto(slug, message)
52+
} else {
53+
err = runPush(args[0], slug, message)
54+
}
55+
if errors.Is(err, huh.ErrUserAborted) {
56+
ui.Info("Cancelled.")
57+
return nil
5058
}
51-
return runPush(args[0], slug, message)
59+
return err
5260
},
5361
}
5462

@@ -395,6 +403,9 @@ func pickOrCreateConfig(token, apiBase string) (string, error) {
395403
fmt.Fprintln(os.Stderr)
396404
choice, err := ui.SelectOption("Push to which config?", options)
397405
if err != nil {
406+
if errors.Is(err, huh.ErrUserAborted) {
407+
return "", huh.ErrUserAborted
408+
}
398409
return "", fmt.Errorf("select config: %w", err)
399410
}
400411

@@ -417,6 +428,9 @@ func promptPushDetails(defaultName string) (string, string, string, error) {
417428
name, err = ui.Input("Config name", "My Mac Setup")
418429
}
419430
if err != nil {
431+
if errors.Is(err, huh.ErrUserAborted) {
432+
return "", "", "", huh.ErrUserAborted
433+
}
420434
return "", "", "", fmt.Errorf("get config name: %w", err)
421435
}
422436
name = strings.TrimSpace(name)
@@ -427,6 +441,9 @@ func promptPushDetails(defaultName string) (string, string, string, error) {
427441
fmt.Fprintln(os.Stderr)
428442
desc, err := ui.Input("Description (optional)", "")
429443
if err != nil {
444+
if errors.Is(err, huh.ErrUserAborted) {
445+
return "", "", "", huh.ErrUserAborted
446+
}
430447
return "", "", "", fmt.Errorf("get description: %w", err)
431448
}
432449
desc = strings.TrimSpace(desc)
@@ -439,6 +456,9 @@ func promptPushDetails(defaultName string) (string, string, string, error) {
439456
}
440457
choice, err := ui.SelectOption("Who can see this config?", options)
441458
if err != nil {
459+
if errors.Is(err, huh.ErrUserAborted) {
460+
return "", "", "", huh.ErrUserAborted
461+
}
442462
return "", "", "", fmt.Errorf("select visibility: %w", err)
443463
}
444464

0 commit comments

Comments
 (0)