Skip to content

Commit 4db2ecd

Browse files
committed
review: add app name validation with flag
1 parent d1376a1 commit 4db2ecd

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

cmd/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func runCreateApp(cmd *cobra.Command, args []string) error {
6868
spinner.Fail("Failed to copy template files")
6969
return fmt.Errorf("failed to copy template files: %w", err)
7070
}
71-
spinner.Success("✔ TypeScript environment set up successfully")
71+
spinner.Success(fmt.Sprintf("✔ %s environment set up successfully", language))
7272

7373
nextSteps := fmt.Sprintf(`Next steps:
7474
brew install onkernel/tap/kernel

cmd/root.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ func init() {
129129
rootCmd.AddCommand(profilesCmd)
130130
rootCmd.AddCommand(proxies.ProxiesCmd)
131131
rootCmd.AddCommand(extensionsCmd)
132-
// Hide create command while WIP
133-
// rootCmd.AddCommand(createCmd)
132+
rootCmd.AddCommand(createCmd)
134133

135134
rootCmd.PersistentPostRunE = func(cmd *cobra.Command, args []string) error {
136135
// running synchronously so we never slow the command

pkg/create/prompts.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/pterm/pterm"
99
)
1010

11+
// validateAppName validates that an app name follows the required format.
12+
// Returns an error if the name is invalid.
1113
func validateAppName(val any) error {
1214
str, ok := val.(string)
1315
if !ok {
@@ -29,11 +31,8 @@ func validateAppName(val any) error {
2931
return nil
3032
}
3133

32-
func PromptForAppName(providedAppName string) (string, error) {
33-
if providedAppName != "" {
34-
return providedAppName, nil
35-
}
36-
34+
// handleAppNamePrompt prompts the user for an app name interactively.
35+
func handleAppNamePrompt() (string, error) {
3736
promptText := fmt.Sprintf("%s (default: %s)", AppNamePrompt, DefaultAppName)
3837
appName, err := pterm.DefaultInteractiveTextInput.
3938
WithDefaultText(promptText).
@@ -42,19 +41,36 @@ func PromptForAppName(providedAppName string) (string, error) {
4241
return "", err
4342
}
4443

45-
// Use default if user just pressed enter without typing anything
4644
if appName == "" {
4745
appName = DefaultAppName
4846
}
4947

50-
// Validate the app name
5148
if err := validateAppName(appName); err != nil {
52-
return "", err
49+
pterm.Warning.Printf("Invalid app name '%s': %v\n", appName, err)
50+
pterm.Info.Println("Please provide a valid app name.")
51+
return handleAppNamePrompt()
5352
}
5453

5554
return appName, nil
5655
}
5756

57+
// PromptForAppName validates the provided app name or prompts the user for one.
58+
// If the provided name is invalid, it shows a warning and prompts the user.
59+
func PromptForAppName(providedAppName string) (string, error) {
60+
// If no app name was provided, prompt the user
61+
if providedAppName == "" {
62+
return handleAppNamePrompt()
63+
}
64+
65+
if err := validateAppName(providedAppName); err != nil {
66+
pterm.Warning.Printf("Invalid app name '%s': %v\n", providedAppName, err)
67+
pterm.Info.Println("Please provide a valid app name.")
68+
return handleAppNamePrompt()
69+
}
70+
71+
return providedAppName, nil
72+
}
73+
5874
func handleLanguagePrompt() (string, error) {
5975
l, err := pterm.DefaultInteractiveSelect.
6076
WithOptions(SupportedLanguages).

0 commit comments

Comments
 (0)