Skip to content

Commit 3830b66

Browse files
committed
Add config command structure with subcommands
Implement the foundation for configuration management in the CLI including: - Main `config` command grouped under "system" - Five subcommands: `set`, `get`, `unset`, `describe`, and `list` - Shell completion for configuration keys across relevant subcommands - Configuration description system with type, description, example, and default fields Examples: - `construct config describe defaults.agent` - Get detailed information about a config key - `construct config set <key> <value>` - Set configuration value - `construct config get <key>` - Get configuration value - `construct config list` - List all configuration values - `construct config unset <key>` - Remove configuration value
1 parent 63a35a1 commit 3830b66

6 files changed

Lines changed: 164 additions & 0 deletions

File tree

frontend/cli/cmd/config.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var configOptions = []string{
8+
"task.default-agent",
9+
"agent.default-model",
10+
}
11+
12+
func NewConfigCmd() *cobra.Command {
13+
cmd := &cobra.Command{
14+
Use: "config",
15+
Short: "Manage configuration",
16+
GroupID: "system",
17+
}
18+
19+
cmd.AddCommand(NewConfigSetCmd())
20+
cmd.AddCommand(NewConfigGetCmd())
21+
cmd.AddCommand(NewConfigUnsetCmd())
22+
cmd.AddCommand(NewConfigDescribeCmd())
23+
cmd.AddCommand(NewConfigListCmd())
24+
25+
return cmd
26+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
type configDescription struct {
10+
Type string
11+
Description string
12+
Example string
13+
Default string
14+
}
15+
16+
var configDescriptions = map[string]configDescription{
17+
"defaults.agent": {
18+
Type: "String (Agent Name or ID)",
19+
Description: "Specifies the default agent to use when running `construct new` without the\n --agent flag. This allows you to set a preferred agent for new conversations.",
20+
Example: "construct config set defaults.agent \"my-favorite-coder\"",
21+
},
22+
}
23+
24+
func NewConfigDescribeCmd() *cobra.Command {
25+
cmd := &cobra.Command{
26+
Use: "describe <key>",
27+
Short: "Describe a configuration value",
28+
Long: `The "describe" command allows you to describe a configuration value`,
29+
Args: cobra.ExactArgs(1),
30+
RunE: func(cmd *cobra.Command, args []string) error {
31+
key := args[0]
32+
description, ok := configDescriptions[key]
33+
if !ok {
34+
return fmt.Errorf("unknown configuration key: %s", key)
35+
}
36+
37+
defaultValue := description.Default
38+
if defaultValue == "" {
39+
defaultValue = "(none)"
40+
}
41+
42+
fmt.Printf("%s\n\n", key)
43+
fmt.Printf(" %s\n\n", description.Description)
44+
fmt.Printf(" Type Default\n")
45+
fmt.Printf(" %-28s %s\n\n", description.Type, defaultValue)
46+
fmt.Printf(" Example: %s\n", description.Example)
47+
48+
return nil
49+
},
50+
}
51+
52+
return cmd
53+
}

frontend/cli/cmd/config_get.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
func NewConfigGetCmd() *cobra.Command {
6+
cmd := &cobra.Command{
7+
Use: "get <key>",
8+
Short: "Get a configuration value",
9+
Long: `The "get" command allows you to get a configuration value`,
10+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
11+
if len(args) == 0 {
12+
return configOptions, cobra.ShellCompDirectiveNoFileComp
13+
}
14+
15+
return []string{}, cobra.ShellCompDirectiveDefault
16+
},
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
return nil
19+
},
20+
}
21+
22+
return cmd
23+
}

frontend/cli/cmd/config_list.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
func NewConfigListCmd() *cobra.Command {
6+
cmd := &cobra.Command{
7+
Use: "list",
8+
Short: "List all configuration values",
9+
Long: `The "list" command allows you to list all configuration values`,
10+
RunE: func(cmd *cobra.Command, args []string) error {
11+
return nil
12+
},
13+
}
14+
15+
return cmd
16+
}

frontend/cli/cmd/config_set.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
func NewConfigSetCmd() *cobra.Command {
6+
cmd := &cobra.Command{
7+
Use: "set <key> <value>",
8+
Short: "Set a configuration value",
9+
Long: `The "config set" command allows you to set a configuration value`,
10+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
11+
if len(args) == 0 {
12+
return configOptions, cobra.ShellCompDirectiveNoFileComp
13+
}
14+
15+
return []string{}, cobra.ShellCompDirectiveDefault
16+
},
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
return nil
19+
},
20+
}
21+
22+
return cmd
23+
}

frontend/cli/cmd/config_unset.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import "github.com/spf13/cobra"
4+
5+
func NewConfigUnsetCmd() *cobra.Command {
6+
cmd := &cobra.Command{
7+
Use: "unset <key>",
8+
Short: "Unset a configuration value",
9+
Long: `The "unset" command allows you to unset a configuration value`,
10+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
11+
if len(args) == 0 {
12+
return configOptions, cobra.ShellCompDirectiveNoFileComp
13+
}
14+
15+
return []string{}, cobra.ShellCompDirectiveDefault
16+
},
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
return nil
19+
},
20+
}
21+
22+
return cmd
23+
}

0 commit comments

Comments
 (0)