|
5 | 5 | "fmt" |
6 | 6 | "os" |
7 | 7 | "path/filepath" |
| 8 | + "sort" |
| 9 | + "strings" |
8 | 10 |
|
9 | 11 | "github.com/kernel/cli/pkg/create" |
10 | 12 | "github.com/pterm/pterm" |
@@ -67,14 +69,74 @@ func (c CreateCmd) Create(ctx context.Context, ci create.CreateInput) error { |
67 | 69 | var createCmd = &cobra.Command{ |
68 | 70 | Use: "create", |
69 | 71 | Short: "Create a new application", |
70 | | - Long: "Commands for creating new Kernel applications", |
71 | | - RunE: runCreateApp, |
| 72 | + Long: buildCreateLongHelp(), |
| 73 | + Example: strings.Join([]string{ |
| 74 | + "create --name my-app --language typescript --template anthropic-computer-use", |
| 75 | + "create -n my-app -l py -t sample-app", |
| 76 | + }, "\n"), |
| 77 | + RunE: runCreateApp, |
72 | 78 | } |
73 | 79 |
|
74 | 80 | func init() { |
75 | 81 | createCmd.Flags().StringP("name", "n", "", "Name of the application") |
76 | | - createCmd.Flags().StringP("language", "l", "", "Language of the application") |
77 | | - createCmd.Flags().StringP("template", "t", "", "Template to use for the application") |
| 82 | + createCmd.Flags().StringP("language", "l", "", fmt.Sprintf("Language of the application (%s)", strings.Join(supportedLanguageDisplay(), ", "))) |
| 83 | + createCmd.Flags().StringP("template", "t", "", "Template to use for the application (see 'kernel create --help' for the full list)") |
| 84 | +} |
| 85 | + |
| 86 | +// supportedLanguageDisplay returns each supported language with its shorthand, |
| 87 | +// e.g. ["typescript|ts", "python|py"], for inline flag-usage hints. |
| 88 | +func supportedLanguageDisplay() []string { |
| 89 | + out := make([]string, 0, len(create.SupportedLanguages)) |
| 90 | + for _, l := range create.SupportedLanguages { |
| 91 | + if s := create.LanguageShorthand(l); s != "" { |
| 92 | + out = append(out, l+"|"+s) |
| 93 | + } else { |
| 94 | + out = append(out, l) |
| 95 | + } |
| 96 | + } |
| 97 | + return out |
| 98 | +} |
| 99 | + |
| 100 | +// buildCreateLongHelp renders the Long help text for `kernel create`, |
| 101 | +// listing supported languages and every template (with descriptions and |
| 102 | +// which languages it supports) so agents and scripts can pick non-interactively. |
| 103 | +func buildCreateLongHelp() string { |
| 104 | + var b strings.Builder |
| 105 | + b.WriteString("Commands for creating new Kernel applications.\n\n") |
| 106 | + b.WriteString("Pass --name, --language and --template to scaffold non-interactively;\n") |
| 107 | + b.WriteString("any omitted flag falls back to an interactive prompt.\n\n") |
| 108 | + |
| 109 | + b.WriteString("Languages:\n") |
| 110 | + for _, l := range create.SupportedLanguages { |
| 111 | + if s := create.LanguageShorthand(l); s != "" { |
| 112 | + fmt.Fprintf(&b, " %s (shorthand: %s)\n", l, s) |
| 113 | + } else { |
| 114 | + fmt.Fprintf(&b, " %s\n", l) |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + keys := make([]string, 0, len(create.Templates)) |
| 119 | + for k := range create.Templates { |
| 120 | + keys = append(keys, k) |
| 121 | + } |
| 122 | + sort.Strings(keys) |
| 123 | + |
| 124 | + keyWidth := 0 |
| 125 | + for _, k := range keys { |
| 126 | + if len(k) > keyWidth { |
| 127 | + keyWidth = len(k) |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + b.WriteString("\nTemplates:\n") |
| 132 | + for _, k := range keys { |
| 133 | + info := create.Templates[k] |
| 134 | + langs := append([]string(nil), info.Languages...) |
| 135 | + sort.Strings(langs) |
| 136 | + fmt.Fprintf(&b, " %-*s %s [%s]\n", keyWidth, k, info.Description, strings.Join(langs, ", ")) |
| 137 | + } |
| 138 | + |
| 139 | + return strings.TrimRight(b.String(), "\n") |
78 | 140 | } |
79 | 141 |
|
80 | 142 | func runCreateApp(cmd *cobra.Command, args []string) error { |
|
0 commit comments