with one click
create-ticloud-cli-command
// Builds TiDB Cloud CLI commands. Use when creating new commands.
// Builds TiDB Cloud CLI commands. Use when creating new commands.
| name | create-ticloud-cli-command |
| description | Builds TiDB Cloud CLI commands. Use when creating new commands. |
| license | Complete terms in LICENSE.txt |
| metadata | {"author":"shiyuhang0"} |
This skill builds TiDB Cloud CLI commands, helping users create new commands with production-ready code.
TiDB Cloud CLI (TiCloud CLI) is a command-line interface for interacting with TiDB Cloud, built on the Cobra library.
Key design of TiDB Cloud CLI:
Built on the Cobra library.
Uses the TiDB Cloud Open API as the client and keeps the SDK inside the project.
Every command supports both interactive and non-interactive modes.
More about TiDB Cloud CLI: references/tidbcloud-cli.md.
More about Cobra: references/cobra.md.
The AI agent must switch to plan mode to collect information from the user and generate a plan first.
Then use agent mode to generate the code.
If the user requires testing, testing takes precedence over implementation. Write tests first, then implement, and finally validate against the tests.
The user must declare the command format; the implementation must comply with that declared format.
Must follow the workflow below:
Always prompt the user: "Do you need to add or update swagger? Please provide the swagger path if you need."
Skip this phase if user does not need.
Once in this phase, follow the guide in references/sdk.md to generate the SDK.
After SDK is generated, ask user to use go>=1.24 to run make generate-mocks manually!
The agent must switch to plan mode in this phase.
The agent must ask the user for the following information during the plan phase:
assets/command.md for the command format template. The commnad flags can be omitted as it can be inferred from swagger.Generate the plan after the user confirms all the information.
The agent must switch to agent mode in this phase. Follow the workflow below:
Ensure generate SDK phase has been done.
Skip this step if the user does not need tests.
Write unit tests following references/ut.md. If the tests need to invoke the command, create the empty command first. See assets/empty.go.
Implement the command following the patterns in assets/example.
The implementation must meet the following requirements:
Command definition: Include name, aliases, example, and other necessary attributes.
Flags definition: Include flag type, description, default value, etc. Infer flag information from the Swagger spec and SDK client parameters. See references/flag.md for more details. Please get customer confirmation once the flags are set.
Flags retrieval: Implement retrieval logic for both interactive and non-interactive modes. For interactive mode, UI is required. The UI is based on the Bubbletea library. See references/ui.md for more details.
Dual mode support: Support both interactive and non-interactive modes. Rules:
MarkInteractive:
!h.IOStreams.CanPrompt, return an error instructing the user to use non-interactive flags.SDK calls: Use the SDK client in api_client.go to call the corresponding method. Note that assets/example does not include this part (it is only a template); it must be included when implementing the actual command.
Skip this step if the user does not need tests.
Run tests with: go test -race -cover -count=1 path -v
For example, to run tests under internal/cli/serverless/branch: go test -race -cover -count=1 ./internal/cli/serverless/branch -v.
Ensure all tests pass. If they do not pass, fix the implementation or the tests.
The final code structure must follow the structure in assets/example:
Command output should follow the patterns in assets/example:
color.GreenString for success. Avoid raw JSON in human mode.output.PrintJson with a stable, predictable payload (e.g. keys like message, resource IDs, items).assets/example/list.go).Example blocks for both interactive and non-interactive usage (see assets/example/create.go and assets/example/list.go).[HINT] Download the complete skill directory including SKILL.md and all related files