Skip to content

Commit f6b4d21

Browse files
committed
prompt for required flags
1 parent 521833b commit f6b4d21

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

cmd/sandbox/create.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222
"unicode"
2323

24+
"github.com/slackapi/slack-cli/internal/iostreams"
2425
"github.com/slackapi/slack-cli/internal/shared"
2526
"github.com/slackapi/slack-cli/internal/slackerror"
2627
"github.com/slackapi/slack-cli/internal/style"
@@ -98,13 +99,6 @@ func NewCreateCommand(clients *shared.ClientFactory) *cobra.Command {
9899
// If one's developer account is managed by multiple Production Slack teams, one of those team IDs must be provided in the command
99100
cmd.Flags().StringVar(&createCmdFlags.owningOrgID, "owning-org-id", "", "Enterprise team ID that manages your developer account, if applicable")
100101

101-
if err := cmd.MarkFlagRequired("name"); err != nil {
102-
panic(err)
103-
}
104-
if err := cmd.MarkFlagRequired("password"); err != nil {
105-
panic(err)
106-
}
107-
108102
return cmd
109103
}
110104

@@ -116,10 +110,38 @@ func runCreateCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
116110
return err
117111
}
118112

113+
name := createCmdFlags.name
114+
if name == "" {
115+
name, err = clients.IO.InputPrompt(
116+
ctx,
117+
"Enter a name for the sandbox",
118+
iostreams.InputPromptConfig{
119+
Required: true,
120+
},
121+
)
122+
if err != nil {
123+
return err
124+
}
125+
}
126+
127+
password := createCmdFlags.password
128+
if password == "" {
129+
password, err = clients.IO.InputPrompt(
130+
ctx,
131+
"Enter a password for the sandbox",
132+
iostreams.InputPromptConfig{
133+
Required: true,
134+
},
135+
)
136+
if err != nil {
137+
return err
138+
}
139+
}
140+
119141
domain := createCmdFlags.domain
120142
if domain == "" {
121143
var err error
122-
domain, err = domainFromName(createCmdFlags.name)
144+
domain, err = domainFromName(name)
123145
if err != nil {
124146
return err
125147
}
@@ -149,9 +171,9 @@ func runCreateCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
149171
}
150172

151173
teamID, sandboxURL, err := clients.API().CreateSandbox(ctx, auth.Token,
152-
createCmdFlags.name,
174+
name,
153175
domain,
154-
createCmdFlags.password,
176+
password,
155177
createCmdFlags.locale,
156178
createCmdFlags.owningOrgID,
157179
templateID,
@@ -170,7 +192,6 @@ func runCreateCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
170192

171193
// getEpochFromTTL parses a time-to-live string (e.g., "1d", "2w", "3mo") and returns the Unix epoch
172194
// when the sandbox will be archived. Supports days (d), weeks (w), and months (mo).
173-
// Minimum is 1 day, maximum is 6 months.
174195
func getEpochFromTTL(ttl string) (int64, error) {
175196
lower := strings.TrimSpace(strings.ToLower(ttl))
176197
if lower == "" {
@@ -206,7 +227,7 @@ func getEpochFromTTL(ttl string) (int64, error) {
206227
return target.Unix(), nil
207228
}
208229

209-
// getEpochFromDate parses a date in yyyy-mm-dd format and returns the Unix epoch at start of that day (UTC).
230+
// getEpochFromDate parses a date in yyyy-mm-dd format and returns the Unix epoch at the start of that day (UTC)
210231
func getEpochFromDate(dateStr string) (int64, error) {
211232
dateFormat := "2006-01-02"
212233
t, err := time.ParseInLocation(dateFormat, dateStr, time.UTC)

internal/slackerror/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ const (
270270
ErrWorkflowNotFound = "workflow_not_found"
271271
ErrYaml = "yaml_error"
272272
ErrSandboxDomainTaken = "domain_taken"
273+
ErrAtActiveSandboxLimit = "at_active_sandbox_limit"
273274
ErrInvalidArchiveTTL = "invalid_archive_ttl"
274275
)
275276

@@ -1628,6 +1629,11 @@ Otherwise start your app for local development with: %s`,
16281629
Message: "This domain has been claimed by another sandbox",
16291630
},
16301631

1632+
ErrAtActiveSandboxLimit: {
1633+
Code: ErrAtActiveSandboxLimit,
1634+
Message: "You've reached the maximum number of active sandboxes",
1635+
},
1636+
16311637
ErrInvalidArchiveTTL: {
16321638
Code: ErrInvalidArchiveTTL,
16331639
Message: "Invalid TTL",

0 commit comments

Comments
 (0)