$npx -y skills add zakelfassi/skills-driven-development --skill flag-addAdd a CLI flag to shipctl end-to-end — argument parser definition, help text, shell completion scripts, documentation, and tests. Use when adding a new option or flag, when extending an existing subcommand, or when asked to "add a --flag-name option".
| 1 | # Flag Add |
| 2 | |
| 3 | Add a new CLI flag to a `shipctl` command end-to-end. |
| 4 | |
| 5 | ## Inputs |
| 6 | - Command path (e.g., `release`, `build cross`, `config set`) |
| 7 | - Flag name (long form, e.g., `--output-dir`) |
| 8 | - Short alias (optional, e.g., `-o`) |
| 9 | - Type (string, bool, integer, path) |
| 10 | - Default value (or `required` if mandatory) |
| 11 | - Description (one-line, used in help text and docs) |
| 12 | |
| 13 | ## Steps |
| 14 | |
| 15 | 1. **Define the flag in the parser** |
| 16 | |
| 17 | For Rust + `clap`: |
| 18 | ```rust |
| 19 | // In the relevant Args struct (src/cmd/{command}.rs) |
| 20 | #[arg(long, short = '{alias}', default_value = "{default}", |
| 21 | help = "{description}")] |
| 22 | pub {flag_name}: {type}, |
| 23 | ``` |
| 24 | |
| 25 | For Go + `cobra`: |
| 26 | ```go |
| 27 | // In the relevant command file (cmd/{command}.go) |
| 28 | cmd.Flags().{TypeVar}(&opts.{FlagName}, "{flag-name}", {default}, "{description}") |
| 29 | ``` |
| 30 | |
| 31 | 2. **Wire the value into the command logic** |
| 32 | Pass the flag value through to whatever downstream call needs it. |
| 33 | Verify the happy path compiles: `cargo check` / `go build ./...`. |
| 34 | |
| 35 | 3. **Update the help text** |
| 36 | Run `shipctl {command} --help` and confirm the flag appears with the correct description and default. |
| 37 | |
| 38 | 4. **Add shell completions** |
| 39 | Regenerate completions (invoke `manpage-sync` skill, or manually): |
| 40 | ```bash |
| 41 | shipctl completions bash > completions/shipctl.bash |
| 42 | shipctl completions zsh > completions/_shipctl |
| 43 | shipctl completions fish > completions/shipctl.fish |
| 44 | ``` |
| 45 | Commit the updated completion files. |
| 46 | |
| 47 | 5. **Update documentation** |
| 48 | Edit `docs/reference/{command}.md`: |
| 49 | - Add a row to the **Flags** table: `| --{flag-name} | {type} | {default} | {description} |` |
| 50 | - Add an **Examples** entry if the flag has a non-obvious use |
| 51 | |
| 52 | 6. **Write or extend a test** |
| 53 | ```rust |
| 54 | // tests/cmd_{command}.rs |
| 55 | #[test] |
| 56 | fn test_{flag_name}_flag() { |
| 57 | let output = Command::cargo_bin("shipctl").unwrap() |
| 58 | .arg("{command}") |
| 59 | .arg("--{flag-name}").arg("{test-value}") |
| 60 | .assert().success(); |
| 61 | // assert output contains expected value |
| 62 | } |
| 63 | ``` |
| 64 | |
| 65 | 7. **Verify the full suite passes** |
| 66 | ```bash |
| 67 | cargo test --workspace |
| 68 | ``` |
| 69 | |
| 70 | ## Conventions |
| 71 | - Long flags are kebab-case (`--output-dir`, not `--outputDir`) |
| 72 | - Boolean flags use `--flag` / `--no-flag` pair when toggling a default-on behavior |
| 73 | - Flags that accept file paths validate existence (return error with `ENOENT` message) |
| 74 | - Help text: imperative mood, no trailing period, max 72 chars |
| 75 | - Short aliases: only for the top 10 most-used flags; don't add new ones without team sign-off |
| 76 | |
| 77 | ## Edge Cases |
| 78 | - **Conflicting short alias:** Run `shipctl --help` on the parent command to audit existing aliases; pick a different letter or omit the alias. |
| 79 | - **Required flag without a default:** Add a clear error message with the flag name and an example invocation. |
| 80 | - **Flag affects multiple subcommands:** Define it at the parent command level with `PersistentFlags()` (cobra) or `Args` flattening (clap). |
| 81 | - **Boolean flag default is `true`:** Document this prominently; many users expect flags to be opt-in. |