Skip to content

Commit ee75a8e

Browse files
committed
prompt when id missing for delete cmd
1 parent f6b4d21 commit ee75a8e

3 files changed

Lines changed: 42 additions & 25 deletions

File tree

cmd/sandbox/create.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,6 @@ var templateNameToID = map[string]int{
4949
"empty": 0, // The sandbox will be empty if the template param is not set
5050
}
5151

52-
// getTemplateID converts a template string to an integer ID
53-
func getTemplateID(template string) (int, error) {
54-
if template == "" {
55-
return 0, nil
56-
}
57-
key := strings.ToLower(strings.TrimSpace(template))
58-
// If the provided string is present in the map, return the ID
59-
if id, ok := templateNameToID[key]; ok {
60-
return id, nil
61-
}
62-
// We also accept an integer passed directly via the flag
63-
if id, err := strconv.Atoi(key); err == nil {
64-
return id, nil
65-
}
66-
return 0, slackerror.New(slackerror.ErrInvalidTemplateID).
67-
WithMessage("Invalid template: %q", template)
68-
}
69-
7052
func NewCreateCommand(clients *shared.ClientFactory) *cobra.Command {
7153
cmd := &cobra.Command{
7254
Use: "create [flags]",
@@ -264,6 +246,24 @@ func domainFromName(name string) (string, error) {
264246
return string(domain), nil
265247
}
266248

249+
// getTemplateID converts a template string to an integer ID
250+
func getTemplateID(template string) (int, error) {
251+
if template == "" {
252+
return 0, nil
253+
}
254+
key := strings.ToLower(strings.TrimSpace(template))
255+
// If the provided string is present in the map, return the ID
256+
if id, ok := templateNameToID[key]; ok {
257+
return id, nil
258+
}
259+
// We also accept an integer passed directly via the flag
260+
if id, err := strconv.Atoi(key); err == nil {
261+
return id, nil
262+
}
263+
return 0, slackerror.New(slackerror.ErrInvalidTemplateID).
264+
WithMessage("Invalid template: %q", template)
265+
}
266+
267267
func printCreateSuccess(cmd *cobra.Command, clients *shared.ClientFactory, teamID, url string) {
268268
ctx := cmd.Context()
269269
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{

cmd/sandbox/delete.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ func NewDeleteCommand(clients *shared.ClientFactory) *cobra.Command {
5151
cmd.Flags().StringVar(&deleteCmdFlags.sandboxID, "sandbox-id", "", "Sandbox team ID to delete")
5252
cmd.Flags().BoolVar(&deleteCmdFlags.force, "force", false, "Skip confirmation prompt")
5353

54-
if err := cmd.MarkFlagRequired("sandbox-id"); err != nil {
55-
panic(err)
56-
}
57-
5854
return cmd
5955
}
6056

@@ -66,13 +62,27 @@ func runDeleteCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
6662
return err
6763
}
6864

65+
sandboxID := deleteCmdFlags.sandboxID
66+
if sandboxID == "" {
67+
sandboxID, err = clients.IO.InputPrompt(
68+
ctx,
69+
"Enter the ID of the sandbox",
70+
iostreams.InputPromptConfig{
71+
Required: true,
72+
},
73+
)
74+
if err != nil {
75+
return err
76+
}
77+
}
78+
6979
skipConfirm := deleteCmdFlags.force
7080
if !skipConfirm {
7181
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
7282
Emoji: "warning",
7383
Text: style.Bold(" Danger zone"),
7484
Secondary: []string{
75-
fmt.Sprintf("Sandbox (%s) and all of its data will be permanently deleted", deleteCmdFlags.sandboxID),
85+
fmt.Sprintf("Sandbox (%s) and all of its data will be permanently deleted", sandboxID),
7686
"This cannot be undone",
7787
},
7888
}))
@@ -93,15 +103,15 @@ func runDeleteCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
93103
}
94104
}
95105

96-
if err := clients.API().DeleteSandbox(ctx, auth.Token, deleteCmdFlags.sandboxID); err != nil {
106+
if err := clients.API().DeleteSandbox(ctx, auth.Token, sandboxID); err != nil {
97107
return err
98108
}
99109

100110
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
101111
Emoji: "white_check_mark",
102112
Text: "Sandbox Deleted",
103113
Secondary: []string{
104-
"Sandbox " + deleteCmdFlags.sandboxID + " has been permanently deleted",
114+
"Sandbox " + sandboxID + " has been permanently deleted",
105115
},
106116
}))
107117

internal/slackerror/errors.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ const (
271271
ErrYaml = "yaml_error"
272272
ErrSandboxDomainTaken = "domain_taken"
273273
ErrAtActiveSandboxLimit = "at_active_sandbox_limit"
274+
ErrInvalidSandboxTeamID = "invalid_sandbox_team_id"
274275
ErrInvalidArchiveTTL = "invalid_archive_ttl"
275276
)
276277

@@ -1634,6 +1635,12 @@ Otherwise start your app for local development with: %s`,
16341635
Message: "You've reached the maximum number of active sandboxes",
16351636
},
16361637

1638+
ErrInvalidSandboxTeamID: {
1639+
Code: ErrInvalidSandboxTeamID,
1640+
Message: "The provided sandbox team ID is invalid",
1641+
Remediation: fmt.Sprintf("List your sandboxes with the %s command to find the ID", style.Commandf("sandbox list", false)),
1642+
},
1643+
16371644
ErrInvalidArchiveTTL: {
16381645
Code: ErrInvalidArchiveTTL,
16391646
Message: "Invalid TTL",

0 commit comments

Comments
 (0)