Skip to content

Commit 3a9abf8

Browse files
authored
list templates + languages in 'kernel create --help' (#160)
1 parent c183fe9 commit 3a9abf8

3 files changed

Lines changed: 98 additions & 4 deletions

File tree

cmd/create.go

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"sort"
9+
"strings"
810

911
"github.com/kernel/cli/pkg/create"
1012
"github.com/pterm/pterm"
@@ -67,14 +69,74 @@ func (c CreateCmd) Create(ctx context.Context, ci create.CreateInput) error {
6769
var createCmd = &cobra.Command{
6870
Use: "create",
6971
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,
7278
}
7379

7480
func init() {
7581
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")
78140
}
79141

80142
func runCreateApp(cmd *cobra.Command, args []string) error {

pkg/create/types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,16 @@ func NormalizeLanguage(language string) string {
5656
return language
5757
}
5858
}
59+
60+
// LanguageShorthand returns the shorthand for a canonical language name,
61+
// or an empty string if the language has no shorthand. Inverse of NormalizeLanguage.
62+
func LanguageShorthand(language string) string {
63+
switch language {
64+
case LanguageTypeScript:
65+
return LanguageShorthandTypeScript
66+
case LanguagePython:
67+
return LanguageShorthandPython
68+
default:
69+
return ""
70+
}
71+
}

pkg/create/types_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,22 @@ func TestNormalizeLanguage(t *testing.T) {
2424
})
2525
}
2626
}
27+
28+
func TestLanguageShorthand(t *testing.T) {
29+
tests := []struct {
30+
input string
31+
expected string
32+
}{
33+
{"typescript", "ts"},
34+
{"python", "py"},
35+
{"ts", ""},
36+
{"unknown", ""},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run(tt.input, func(t *testing.T) {
41+
got := LanguageShorthand(tt.input)
42+
assert.Equal(t, tt.expected, got)
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)