Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,30 @@ Skills are reusable capabilities that can be discovered and executed by AI agent
1. Create `pkg/cmd/<command>.go` with a `New<Command>Cmd()` function that returns `*cobra.Command`
2. In the `New<Command>Cmd()` function:
- Create and configure the `cobra.Command`
- **IMPORTANT**: Always define the `Args` field to specify argument validation
- Set up any flags or subcommands
- Return the configured command
3. Register the command in `pkg/cmd/root.go` by adding `rootCmd.AddCommand(New<Command>Cmd())` in the `NewRootCmd()` function
4. Create corresponding test file `pkg/cmd/<command>_test.go`
5. In tests, create command instances using `NewRootCmd()` or `New<Command>Cmd()` as needed

**Command Argument Validation:**

All commands **MUST** declare the `Args` field to specify argument validation behavior. Common options:
- `cobra.NoArgs` - Command accepts no arguments (most common for parent commands and no-arg commands)
- `cobra.ExactArgs(n)` - Command requires exactly n arguments
- `cobra.MinimumNArgs(n)` - Command requires at least n arguments
- `cobra.MaximumNArgs(n)` - Command accepts up to n arguments
- `cobra.RangeArgs(min, max)` - Command accepts between min and max arguments

Example:
```go
// pkg/cmd/example.go
func NewExampleCmd() *cobra.Command {
return &cobra.Command{
Use: "example",
Short: "An example command",
Args: cobra.NoArgs, // Always declare Args field
Run: func(cmd *cobra.Command, args []string) {
// Command logic here
},
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewListCmd() *cobra.Command {
Use: "list",
Short: workspaceListCmd.Short,
Long: workspaceListCmd.Long,
Args: workspaceListCmd.Args,
PreRunE: workspaceListCmd.PreRunE,
RunE: workspaceListCmd.RunE,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "kortex-cli",
Short: "Launch and manage AI agent workspaces with custom configurations",
Args: cobra.NoArgs,
}

// Add subcommands
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewWorkspaceCmd() *cobra.Command {
Use: "workspace",
Short: "Manage workspaces",
Long: "Manage workspaces registered with kortex-cli init",
Args: cobra.NoArgs,
}

// Add subcommands
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/workspace_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func NewWorkspaceListCmd() *cobra.Command {
Use: "list",
Short: "List all registered workspaces",
Long: "List all workspaces registered with kortex-cli init",
Args: cobra.NoArgs,
PreRunE: c.preRun,
RunE: c.run,
}
Expand Down