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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin/
.agents/
.codex/
ucloud-sandbox-cli
.idea
14 changes: 11 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ make test
## 项目结构

### `cmd/`
所有CLI命令的实现都放在此目录。每个命令通过 `New<CommandName>Cmd()` 函数返回 `*cobra.Command`。
所有CLI命令的实现都放在此目录,每个命令组一个子包(如 `cmd/sandbox/`、`cmd/auth/`)。

**命令组:** 子包导出 `Command() *cobra.Command`,返回命令组并注册其下的子命令;顶层命令组在 `main.go` 中注册。

**子命令:** 每个子命令是一个实现了 `cmd.Operation` 接口的 `<name>Operation` 结构体(未导出),flag 绑定到结构体字段:
- `Command() *cobra.Command`:定义 `Use`、`Short`、`Args` 和 flags
- `Run(ctx cmd.OperationContext) error`:执行命令,通过 `ctx.Client` 调用 SDK

注册时用 `cmd.Build(&xxxOperation{})` 包装,它会加载配置并创建 SDK client;只读写本地配置、不需要 client 的命令(如 `login`、`update`)用 `cmd.BuildLocal`。

**新增命令时需要:**
1. 参考现有命令的实现方式(如 `login.go`、`logout.go`、`region.go`)
1. 参考现有命令的实现方式(如 `cmd/sandbox/kill.go`、`cmd/auth/region.go`)
2. 遵循相同的代码风格和错误处理模式
3. 命令函数命名规范:`New<CommandName>Cmd()`
3. 命名规范:命令组为 `Command()`,子命令为 `<name>Operation`

### `internal/`
存放CLI使用的公用包
Expand Down
20 changes: 20 additions & 0 deletions cmd/benchmark/benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package benchmark

import (
"github.com/spf13/cobra"
"github.com/ucloud/ucloud-sandbox-cli/cmd"
)

// Command returns the root benchmark command group.
func Command() *cobra.Command {
c := &cobra.Command{
Use: "benchmark",
Aliases: []string{"bench"},
Short: "Benchmark the sandbox service",
}
c.AddCommand(cmd.Build(&createOperation{}))
c.AddCommand(cmd.Build(&healthOperation{}))
c.AddCommand(cmd.Build(&lifecycleOperation{}))
c.AddCommand(cmd.Build(&snapshotOperation{}))
return c
}
Loading
Loading