You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/NEW_COMMANDS.md
+8-11Lines changed: 8 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ use crate::output::{OutputFormat, Outputable};
56
56
#[derive(Args, Debug)]
57
57
#[command(after_help ="\
58
58
Examples:
59
-
code_search <name> --arg value # Example usage")]
59
+
code_search code <name> --arg value # Example usage")]
60
60
pubstruct <Name>Cmd {
61
61
/// Description of the argument
62
62
#[arg(short, long)]
@@ -148,34 +148,31 @@ impl Outputable for <Name>Result {
148
148
149
149
See [examples/output_tests.rs.example](./examples/output_tests.rs.example) for a reference showing the snapshot testing pattern. The example includes a helper for generating the actual output values to use in your snapshots.
150
150
151
-
### 8. Register the command (`src/commands/mod.rs`)
151
+
### 8. Register the command
152
152
153
-
Add the module declaration and public export:
153
+
Add the module declaration and public export in `src/commands/mod.rs`:
154
154
155
155
```rust
156
156
mod <name>;
157
157
158
158
pubuse <name>::<Name>Cmd;
159
159
```
160
160
161
-
Add the variant to the `Command` enum:
161
+
Add the variant to the `CodeCommand` enum in `src/commands/code.rs`:
162
162
163
163
```rust
164
164
#[derive(Subcommand, Debug)]
165
165
#[enum_dispatch(CommandRunner)]
166
-
pubenumCommand {
166
+
pubenumCodeCommand {
167
167
/// Existing commands...
168
168
Import(ImportCmd),
169
169
170
170
/// Description of your command
171
171
<Name>(<Name>Cmd),
172
-
173
-
#[command(external_subcommand)]
174
-
Unknown(Vec<String>),
175
172
}
176
173
```
177
174
178
-
**Note:** The `#[enum_dispatch(CommandRunner)]` attribute is already on the `Command` enum. The `enum_dispatch` crate automatically generates the dispatch logic for all variants. You do NOT need to add a match arm in `Command::run()` - the `CommandRunner` implementation you added to your command's `mod.rs` file (in step 2) is all that's needed!
175
+
**Note:** The top-level `Command` enum in `mod.rs` has only `Setup` and `Code(CodeCommand)`. All code analysis commands are registered in `CodeCommand` (in `code.rs`), not in `Command`. The `#[enum_dispatch(CommandRunner)]` attribute automatically generates dispatch logic for all variants. You do NOT need to add a match arm — the `CommandRunner` implementation you added to your command's `mod.rs` file (in step 2) is all that's needed!
179
176
180
177
The dispatch is handled entirely by the `enum_dispatch` procedural macro at compile time, which is faster and more maintainable than manual match arms.
181
178
@@ -184,7 +181,7 @@ The dispatch is handled entirely by the `enum_dispatch` procedural macro at comp
184
181
```bash
185
182
cargo build
186
183
cargo test
187
-
cargo run -- <name> --help
184
+
cargo run -- code <name> --help
188
185
```
189
186
190
187
## Checklist
@@ -219,7 +216,7 @@ cargo run -- <name> --help
219
216
-[ ] Registered command in `src/commands/mod.rs`
220
217
-[ ] Added module declaration: `mod <name>;`
221
218
-[ ] Added public export: `pub use <name>::<Name>Cmd;`
222
-
-[ ] Added enum variant to `Command` enum (dispatch is automatic via `#[enum_dispatch(CommandRunner)]`)
219
+
-[ ] Added enum variant to `CodeCommand` in `src/commands/code.rs` (dispatch is automatic via `#[enum_dispatch(CommandRunner)]`)
223
220
-[ ]**No match arm needed** - enum_dispatch handles it automatically!
0 commit comments