Skip to content

Commit edcda2b

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

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

cmd/sandbox/create.go

Lines changed: 32 additions & 9 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,6 +110,36 @@ 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+
createCmdFlags.name = name
127+
128+
password := createCmdFlags.password
129+
if password == "" {
130+
password, err = clients.IO.InputPrompt(
131+
ctx,
132+
"Enter a password for the sandbox",
133+
iostreams.InputPromptConfig{
134+
Required: true,
135+
},
136+
)
137+
if err != nil {
138+
return err
139+
}
140+
}
141+
createCmdFlags.password = password
142+
119143
domain := createCmdFlags.domain
120144
if domain == "" {
121145
var err error
@@ -170,7 +194,6 @@ func runCreateCommand(cmd *cobra.Command, clients *shared.ClientFactory) error {
170194

171195
// getEpochFromTTL parses a time-to-live string (e.g., "1d", "2w", "3mo") and returns the Unix epoch
172196
// when the sandbox will be archived. Supports days (d), weeks (w), and months (mo).
173-
// Minimum is 1 day, maximum is 6 months.
174197
func getEpochFromTTL(ttl string) (int64, error) {
175198
lower := strings.TrimSpace(strings.ToLower(ttl))
176199
if lower == "" {
@@ -206,7 +229,7 @@ func getEpochFromTTL(ttl string) (int64, error) {
206229
return target.Unix(), nil
207230
}
208231

209-
// getEpochFromDate parses a date in yyyy-mm-dd format and returns the Unix epoch at start of that day (UTC).
232+
// getEpochFromDate parses a date in yyyy-mm-dd format and returns the Unix epoch at the start of that day (UTC)
210233
func getEpochFromDate(dateStr string) (int64, error) {
211234
dateFormat := "2006-01-02"
212235
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)