Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new command implementation checklist doc #269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,50 @@ $HOME/go/bin/ginkgo -v -focus="Cluster" # To run all tests related to Cluster.
$HOME/go/bin/ginkgo -v -focus="Pausing cluster|Resuming cluster" # To run all tests related to Pausing/Resuming cluster
```
It can be a regex as well inside focus or text from either of `Context`, `It` or `Describe` block. You can read more about it [here](https://onsi.github.io/ginkgo/#description-based-filtering).

## New Command Checklist for YBM CLI

This document serves as a checklist to guide the process of adding a new command/subcommand to the YBM CLI tool.
Follow each step to ensure the command is implemented, tested, and documented consistently with YBM CLI standards.

### 1. Command Implementation

The following for each command should work(of course including the intended functionality):
- [ ] **Output Format Support**:
- [ ] Ensure support for output formats: **table**, **JSON**, and **pretty**. Ideally, this will be taken care automatically when you implement your formatter using `internal/formatter` package.
- **Table**: Display data in a structured table format, suitable for terminal viewing. Refer commands like `$ ybm cluster list`. THis is default output format.
- **JSON**: Provide output in raw JSON format for easy parsing.
- **Pretty JSON**: Format JSON output in a human-readable way, with indentation.
- [ ] Test output in each format to verify correct display and structure.
- [ ] **Async Operation Support**:
- [ ] For commands with asynchronous operations (e.g. `cluster pause` or `resume` etc), implement support for the `--wait` flag.
- When `--wait` is specified, the command should wait until the operation completes and display the final status. This flag is globally added to all commands, to implement it you need to call [this](https://github.com/yugabyte/ybm-cli/blob/c24aca2700307de5d8f91735e9e75659f1c25847/internal/client/client.go#L1327) i.e. `authApi.WaitForTaskCompletion(...)`. Refer [this](https://github.com/yugabyte/ybm-cli/blob/c24aca2700307de5d8f91735e9e75659f1c25847/cmd/cluster/log-exporter/query_log_exporter.go#L251) for example.

### 2. Testing

- **Unit Tests**: Write unit tests for the command including but not limited to:
- [ ] A test case for required params not provided.
- [ ] A test to assert Table output format.
- [ ] A test to assert Json output format.
- [ ] When mocking an API call, verify that the call was actually made. For example, use `Expect(server.ReceivedRequests()).Should(HaveLen(1))`. For `POST`, `PUT`, or `PATCH` requests, you can also assert the request body content as follows:
```shell
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodPut, "/some/path"),
# Here we are asserting on the expected Request Body
ghttp.VerifyJSON(`{"expectedField1":"val1",...}`),
ghttp.RespondWithJSONEncodedPtr(&statusCode, resp),
)
)
```
This approach is useful for confirming that all necessary fields were included when building the request model, helping catch any omissions in the request structure.

- **Run Tests**: Execute the test suite and verify all tests pass.

### 3. Documentation
To generate doc, run:
```shell
cd ~/code/ybm-cli/
make doc
```
It will automatically generate document for each subcommand.