(ch *cmdutil.Helper)
| 19 | ) |
| 20 | |
| 21 | func InitCmd(ch *cmdutil.Helper) *cobra.Command { |
| 22 | var olap string |
| 23 | var example string |
| 24 | var agent string |
| 25 | |
| 26 | exampleOptions, _ := examples.List() |
| 27 | |
| 28 | var long strings.Builder |
| 29 | long.WriteString("Initialize a new Rill project. Use flags to customize the project or run interactively to be prompted for each option.") |
| 30 | if len(exampleOptions) > 0 { |
| 31 | long.WriteString("\n\nAvailable example projects:\n") |
| 32 | for _, ex := range exampleOptions { |
| 33 | fmt.Fprintf(&long, " - %s (%s)\n", ex.Name, ex.OLAPConnector) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | initCmd := &cobra.Command{ |
| 38 | Use: "init [<path>]", |
| 39 | Short: "Initialize a new Rill project", |
| 40 | Long: long.String(), |
| 41 | Example: ` # Interactive initialization (prompts for all options) |
| 42 | rill init |
| 43 | |
| 44 | # Create an empty DuckDB project with Claude agent instructions |
| 45 | rill init my-project --olap duckdb --agent claude |
| 46 | |
| 47 | # Add Claude agent instructions to an existing Rill project |
| 48 | rill init ./existing-project --agent claude`, |
| 49 | RunE: func(cmd *cobra.Command, args []string) error { |
| 50 | // Assess what flags were set |
| 51 | numFlags := 0 |
| 52 | explicitOlap := false |
| 53 | explicitAgent := false |
| 54 | if cmd.Flags().Changed("olap") { |
| 55 | numFlags++ |
| 56 | explicitOlap = true |
| 57 | } |
| 58 | if cmd.Flags().Changed("example") { |
| 59 | numFlags++ |
| 60 | } |
| 61 | if cmd.Flags().Changed("agent") { |
| 62 | numFlags++ |
| 63 | explicitAgent = true |
| 64 | } |
| 65 | |
| 66 | // Resolve project path: |
| 67 | // - If a path arg is provided, use it directly. |
| 68 | // - If cwd contains rill.yaml, default to cwd. |
| 69 | // - Otherwise prompt interactively. |
| 70 | var projectPath string |
| 71 | if len(args) > 0 { |
| 72 | projectPath = args[0] |
| 73 | } else if cmdutil.HasRillProject(".") { |
| 74 | projectPath = "." |
| 75 | } else { |
| 76 | if !ch.Interactive { |
| 77 | return fmt.Errorf("project path argument is required when not running interactively") |
| 78 | } |
no test coverage detected