Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 72 additions & 4 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"

"github.com/kernel/cli/pkg/create"
"github.com/pterm/pterm"
Expand Down Expand Up @@ -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
}
Comment thread
cursor[bot] marked this conversation as resolved.

// 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 {
Expand Down
Loading