|
1 | 1 | --- |
2 | | -description: Add a new CLI command to HawkOp |
| 2 | +description: Add a new CLI command to HawkOp (with design review + test-first workflow) |
3 | 3 | --- |
4 | 4 |
|
5 | 5 | Help me add a new command to the HawkOp CLI. |
6 | 6 |
|
7 | | -**Before designing, invoke the `cli-designer` skill** to ensure the command follows clig.dev and 12-Factor CLI principles. |
| 7 | +## Phase 1: Design (before writing any implementation code) |
8 | 8 |
|
9 | | -## Questions to Answer |
| 9 | +### 1.1 Gather Requirements |
10 | 10 |
|
| 11 | +Answer these questions with the user: |
11 | 12 | 1. What should the command do? |
12 | | -2. What command name should be added? |
13 | | -3. What subcommands (if any) should it have? |
14 | | -4. What flags does it need? (prefer flags over multiple positional args) |
15 | | -5. What arguments does it need? (max 1 type of positional arg) |
16 | | - |
17 | | -## Implementation Checklist |
18 | | - |
19 | | -- [ ] Add help text with examples in `after_help` |
20 | | -- [ ] Support `--format json` for machine-readable output |
21 | | -- [ ] Use stdout for data, stderr for messages |
22 | | -- [ ] Return non-zero exit code on failure |
23 | | -- [ ] Add navigation hints (`→ hawkop next-command`) |
24 | | -- [ ] Test with pipes: `hawkop cmd | jq` |
25 | | - |
26 | | -## Implementation Steps |
27 | | - |
28 | | -1. Add API models in `src/client/mod.rs` |
29 | | -2. Add trait method to `StackHawkApi` trait |
30 | | -3. Implement in `src/client/stackhawk.rs` |
31 | | -4. Add display model in `src/models/display.rs` |
32 | | -5. Add CLI command enum in `src/cli/mod.rs` |
33 | | -6. Create handler in `src/cli/<command>.rs` |
34 | | -7. Wire up in `src/main.rs` |
35 | | - |
36 | | -Follow patterns in `src/cli/` and the cli-designer skill's `patterns.md`. |
| 13 | +2. What command name and subcommands? |
| 14 | +3. What flags and arguments? (prefer flags over multiple positional args) |
| 15 | +4. What API endpoint(s) does it call? (check `stackhawk-api.md` and `api-quirks.md`) |
| 16 | + |
| 17 | +### 1.2 Invoke CLI Designer |
| 18 | + |
| 19 | +**Invoke the `cli-designer` skill** to design the interface. Verify: |
| 20 | +- Command follows clig.dev and 12-Factor CLI principles |
| 21 | +- Args vs flags decision is correct |
| 22 | +- Help text includes examples in `after_help` |
| 23 | +- Matches existing HawkOp patterns (`--org`, `--format`, `--limit`, etc.) |
| 24 | + |
| 25 | +### 1.3 Check Existing Patterns |
| 26 | + |
| 27 | +Before implementing, study the closest existing command: |
| 28 | +- Read `src/cli/` files for a similar command (e.g., `scan.rs` for list+detail, `team.rs` for CRUD) |
| 29 | +- Read `src/client/api/` for the API integration pattern |
| 30 | +- Read `src/models/display/` for the display model pattern |
| 31 | +- Check `src/client/mod.rs` for trait method conventions |
| 32 | + |
| 33 | +### 1.4 Check API Quirks |
| 34 | + |
| 35 | +Read `.claude/skills/stackhawk-api-sherpa/api-quirks.md` to check if the endpoint has known quirks (field naming, replace-all PUT behavior, removed endpoints, etc.). |
| 36 | + |
| 37 | +## Phase 2: Test-First Contract |
| 38 | + |
| 39 | +### 2.1 Write Test Stubs First |
| 40 | + |
| 41 | +Before implementing the command, create test stubs that define the expected behavior: |
| 42 | + |
| 43 | +**Unit test** in the relevant source file: |
| 44 | +```rust |
| 45 | +#[cfg(test)] |
| 46 | +mod tests { |
| 47 | + // Test that the command handler produces expected output |
| 48 | + // Test error cases (not found, invalid args) |
| 49 | + // Test JSON format output |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +**Functional test** in `tests/functional/`: |
| 54 | +- Add to the appropriate test file (read_tests.rs, mutation_tests.rs, etc.) |
| 55 | +- At minimum, write stubs for: |
| 56 | + - Happy-path test (command runs successfully) |
| 57 | + - Error-path test (invalid input, not-found) |
| 58 | + - JSON output test (`--format json` produces valid JSON) |
| 59 | + |
| 60 | +### 2.2 Update Coverage Script |
| 61 | + |
| 62 | +Add the new command to `scripts/check-test-coverage.sh` so it's tracked: |
| 63 | +```bash |
| 64 | +check_coverage "hawkop <cmd> <subcmd>" "test_<cmd>_<subcmd>|\"<cmd>\".*\"<subcmd>\"" |
| 65 | +``` |
| 66 | + |
| 67 | +## Phase 3: Implementation |
| 68 | + |
| 69 | +Follow this order (matches CLAUDE.md "Adding New Commands"): |
| 70 | + |
| 71 | +1. **API models** — `src/client/models/<resource>.rs` |
| 72 | + - `#[serde(rename_all = "camelCase")]` |
| 73 | + - Use `#[serde(default)]` for optional fields |
| 74 | + - Check `stackhawk-openapi.json` for exact field names |
| 75 | +2. **Trait method** — `src/client/mod.rs` |
| 76 | +3. **API implementation** — `src/client/api/` (or `src/client/stackhawk.rs`) |
| 77 | +4. **Mock implementation** — `src/client/mock.rs` |
| 78 | +5. **Display model** — `src/models/display/<resource>.rs` |
| 79 | +6. **CLI command enum** — `src/cli/mod.rs` |
| 80 | +7. **Handler** — `src/cli/<command>.rs` |
| 81 | +8. **Main routing** — `src/main.rs` |
| 82 | + |
| 83 | +## Phase 4: Verification |
| 84 | + |
| 85 | +### 4.1 Run Tests |
| 86 | +```bash |
| 87 | +cargo test # All unit/integration tests |
| 88 | +cargo clippy -- -D warnings # Lint check |
| 89 | +``` |
| 90 | + |
| 91 | +### 4.2 Run CLI Design Checklist |
| 92 | + |
| 93 | +Verify against `docs/CLI_DESIGN_PRINCIPLES.md`: |
| 94 | +- [ ] `-h`/`--help` display useful help with examples |
| 95 | +- [ ] `--format json` produces valid JSON parseable by `jq` |
| 96 | +- [ ] Data on stdout, messages on stderr |
| 97 | +- [ ] Non-zero exit on failure |
| 98 | +- [ ] Navigation hints (`-> hawkop next-command`) |
| 99 | +- [ ] Works when piped (`hawkop cmd | jq`) |
| 100 | +- [ ] No ANSI codes when not TTY |
| 101 | + |
| 102 | +### 4.3 Run Functional Tests |
| 103 | +```bash |
| 104 | +HAWKOP_PROFILE=test HAWKOP_FUNCTIONAL_TESTS_CONFIRM=yes \ |
| 105 | + cargo test --features functional-tests --test functional -- --test-threads=1 --nocapture "<test_name>" |
| 106 | +``` |
| 107 | + |
| 108 | +### 4.4 Check Test Coverage |
| 109 | +```bash |
| 110 | +./scripts/check-test-coverage.sh |
| 111 | +``` |
| 112 | + |
| 113 | +## Phase 5: Documentation |
| 114 | + |
| 115 | +- [ ] Update `docs/CLI_REFERENCE.md` with the new command |
| 116 | +- [ ] Update `docs/ROADMAP.md` if this completes a planned endpoint |
| 117 | +- [ ] Add entry to `CHANGELOG.md` under `[Unreleased]` |
| 118 | +- [ ] Update `CLAUDE.md` command list if a new top-level command |
0 commit comments