Skip to content

Commit 92e44c6

Browse files
acmoreclaude
andcommitted
feat(config): rewrite template system with text/template and embed
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d677e17 commit 92e44c6

3 files changed

Lines changed: 222 additions & 210 deletions

File tree

internal/cli/init.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import (
1111

1212
func newInitCmd(opts *Options) *cobra.Command {
1313
var force bool
14-
var templateName string
14+
var templateRef string
15+
var yes bool
16+
var nameOverride string
17+
var nsOverride string
1518

1619
cmd := &cobra.Command{
1720
Use: "init",
@@ -31,23 +34,47 @@ func newInitCmd(opts *Options) *cobra.Command {
3134
return fmt.Errorf("config already exists at %q (use --force to overwrite)", abs)
3235
}
3336

34-
if err := os.MkdirAll(filepath.Dir(abs), 0o755); err != nil {
35-
return fmt.Errorf("create parent directory: %w", err)
37+
vars := config.NewTemplateVars()
38+
if nameOverride != "" {
39+
vars.Name = nameOverride
40+
}
41+
if nsOverride != "" {
42+
vars.Namespace = nsOverride
3643
}
37-
tpl, err := config.TemplateByName(templateName)
44+
if vars.Name == "" {
45+
wd, _ := os.Getwd()
46+
if wd != "" {
47+
vars.Name = filepath.Base(wd)
48+
} else {
49+
vars.Name = "my-project"
50+
}
51+
}
52+
53+
// TODO: interactive prompts will be added in Task 8/9
54+
// For now, non-interactive only (--yes is implicit until prompts are wired)
55+
_ = yes
56+
57+
rendered, err := config.RenderTemplate(templateRef, vars)
3858
if err != nil {
3959
return err
4060
}
41-
if err := os.WriteFile(abs, []byte(tpl), 0o644); err != nil {
61+
62+
if err := os.MkdirAll(filepath.Dir(abs), 0o755); err != nil {
63+
return fmt.Errorf("create parent directory: %w", err)
64+
}
65+
if err := os.WriteFile(abs, []byte(rendered), 0o644); err != nil {
4266
return fmt.Errorf("write config %q: %w", abs, err)
4367
}
4468

45-
fmt.Fprintf(cmd.OutOrStdout(), "Created %s\n", abs)
69+
fmt.Fprintf(cmd.OutOrStdout(), "Wrote %s\n", abs)
4670
return nil
4771
},
4872
}
4973

5074
cmd.Flags().BoolVar(&force, "force", false, "Overwrite an existing config file")
51-
cmd.Flags().StringVar(&templateName, "template", "basic", "Template to use (basic|gpu|llm-stack)")
75+
cmd.Flags().StringVar(&templateRef, "template", "basic", "Template: built-in name, file path, or URL")
76+
cmd.Flags().BoolVar(&yes, "yes", false, "Non-interactive mode, accept all defaults")
77+
cmd.Flags().StringVar(&nameOverride, "name", "", "Environment name")
78+
cmd.Flags().StringVar(&nsOverride, "namespace", "", "Namespace")
5279
return cmd
5380
}

0 commit comments

Comments
 (0)