From 8a9cd38e59ce88025805d611670371d8a6c86bd7 Mon Sep 17 00:00:00 2001 From: masnwilliams <43387599+masnwilliams@users.noreply.github.com> Date: Tue, 12 May 2026 00:18:18 +0000 Subject: [PATCH 1/2] list available templates and languages in `kernel create --help` Generates the Long help text dynamically from create.Templates and create.SupportedLanguages so scripts and agents can pick `--language` and `--template` non-interactively without falling into the prompt. Co-Authored-By: Claude Opus 4.7 --- cmd/create.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 7daf35e1..b6fcde37 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "path/filepath" + "sort" + "strings" "github.com/kernel/cli/pkg/create" "github.com/pterm/pterm" @@ -67,14 +69,80 @@ func (c CreateCmd) Create(ctx context.Context, ci create.CreateInput) error { var createCmd = &cobra.Command{ Use: "create", Short: "Create a new application", - Long: "Commands for creating new Kernel applications", - RunE: runCreateApp, + Long: buildCreateLongHelp(), + Example: strings.Join([]string{ + "create --name my-app --language typescript --template anthropic-computer-use", + "create -n my-app -l py -t sample-app", + }, "\n"), + RunE: runCreateApp, } func init() { createCmd.Flags().StringP("name", "n", "", "Name of the application") - createCmd.Flags().StringP("language", "l", "", "Language of the application") - createCmd.Flags().StringP("template", "t", "", "Template to use for the application") + createCmd.Flags().StringP("language", "l", "", fmt.Sprintf("Language of the application (%s)", strings.Join(supportedLanguageDisplay(), ", "))) + createCmd.Flags().StringP("template", "t", "", "Template to use for the application (see 'kernel create --help' for the full list)") +} + +// supportedLanguageDisplay returns each supported language with its shorthand, +// e.g. ["typescript|ts", "python|py"], for inline flag-usage hints. +func supportedLanguageDisplay() []string { + out := make([]string, 0, len(create.SupportedLanguages)) + for _, l := range create.SupportedLanguages { + switch l { + case create.LanguageTypeScript: + out = append(out, l+"|"+create.LanguageShorthandTypeScript) + case create.LanguagePython: + out = append(out, l+"|"+create.LanguageShorthandPython) + default: + out = append(out, l) + } + } + return out +} + +// buildCreateLongHelp renders the Long help text for `kernel create`, +// listing supported languages and every template (with descriptions and +// which languages it supports) so agents and scripts can pick non-interactively. +func buildCreateLongHelp() string { + var b strings.Builder + b.WriteString("Commands for creating new Kernel applications.\n\n") + b.WriteString("Pass --name, --language and --template to scaffold non-interactively;\n") + b.WriteString("any omitted flag falls back to an interactive prompt.\n\n") + + b.WriteString("Languages:\n") + for _, l := range create.SupportedLanguages { + switch l { + case create.LanguageTypeScript: + fmt.Fprintf(&b, " %s (shorthand: %s)\n", l, create.LanguageShorthandTypeScript) + case create.LanguagePython: + fmt.Fprintf(&b, " %s (shorthand: %s)\n", l, create.LanguageShorthandPython) + default: + fmt.Fprintf(&b, " %s\n", l) + } + } + + keys := make([]string, 0, len(create.Templates)) + for k := range create.Templates { + keys = append(keys, k) + } + sort.Strings(keys) + + keyWidth := 0 + for _, k := range keys { + if len(k) > keyWidth { + keyWidth = len(k) + } + } + + b.WriteString("\nTemplates:\n") + for _, k := range keys { + info := create.Templates[k] + langs := append([]string(nil), info.Languages...) + sort.Strings(langs) + fmt.Fprintf(&b, " %-*s %s [%s]\n", keyWidth, k, info.Description, strings.Join(langs, ", ")) + } + + return strings.TrimRight(b.String(), "\n") } func runCreateApp(cmd *cobra.Command, args []string) error { From 632958373dc64333927de6b988fd8f7f157c635f Mon Sep 17 00:00:00 2001 From: masnwilliams <43387599+masnwilliams@users.noreply.github.com> Date: Tue, 12 May 2026 00:54:14 +0000 Subject: [PATCH 2/2] dedup language-shorthand mapping with LanguageShorthand helper Introduce LanguageShorthand as the inverse of NormalizeLanguage and route the two help-text call sites through it so adding a new language with a shorthand only requires updating types.go. Co-Authored-By: Claude Opus 4.7 --- cmd/create.go | 18 ++++++------------ pkg/create/types.go | 13 +++++++++++++ pkg/create/types_test.go | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index b6fcde37..bf101ef3 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -88,12 +88,9 @@ func init() { func supportedLanguageDisplay() []string { out := make([]string, 0, len(create.SupportedLanguages)) for _, l := range create.SupportedLanguages { - switch l { - case create.LanguageTypeScript: - out = append(out, l+"|"+create.LanguageShorthandTypeScript) - case create.LanguagePython: - out = append(out, l+"|"+create.LanguageShorthandPython) - default: + if s := create.LanguageShorthand(l); s != "" { + out = append(out, l+"|"+s) + } else { out = append(out, l) } } @@ -111,12 +108,9 @@ func buildCreateLongHelp() string { b.WriteString("Languages:\n") for _, l := range create.SupportedLanguages { - switch l { - case create.LanguageTypeScript: - fmt.Fprintf(&b, " %s (shorthand: %s)\n", l, create.LanguageShorthandTypeScript) - case create.LanguagePython: - fmt.Fprintf(&b, " %s (shorthand: %s)\n", l, create.LanguageShorthandPython) - default: + if s := create.LanguageShorthand(l); s != "" { + fmt.Fprintf(&b, " %s (shorthand: %s)\n", l, s) + } else { fmt.Fprintf(&b, " %s\n", l) } } diff --git a/pkg/create/types.go b/pkg/create/types.go index 05e76bcb..35c32711 100644 --- a/pkg/create/types.go +++ b/pkg/create/types.go @@ -56,3 +56,16 @@ func NormalizeLanguage(language string) string { return language } } + +// LanguageShorthand returns the shorthand for a canonical language name, +// or an empty string if the language has no shorthand. Inverse of NormalizeLanguage. +func LanguageShorthand(language string) string { + switch language { + case LanguageTypeScript: + return LanguageShorthandTypeScript + case LanguagePython: + return LanguageShorthandPython + default: + return "" + } +} diff --git a/pkg/create/types_test.go b/pkg/create/types_test.go index 723fba9f..9416de37 100644 --- a/pkg/create/types_test.go +++ b/pkg/create/types_test.go @@ -24,3 +24,22 @@ func TestNormalizeLanguage(t *testing.T) { }) } } + +func TestLanguageShorthand(t *testing.T) { + tests := []struct { + input string + expected string + }{ + {"typescript", "ts"}, + {"python", "py"}, + {"ts", ""}, + {"unknown", ""}, + } + + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + got := LanguageShorthand(tt.input) + assert.Equal(t, tt.expected, got) + }) + } +}