pub fn scaffold_command(
name: &str,
target: &CommandTarget,
project_root: &Path,
) -> Result<ScaffoldReport, ScaffoldError>Expand description
Write a management command and register it.
Two targets, one shape. Either way the command lands in a
commands/<name>.rs next to a commands/mod.rs whose all() function
is the registry, and the registry is wired into the thing that owns it:
--in root --in <plugin>
src/ plugins/<plugin>/src/
main.rs .commands(all()) lib.rs fn commands() -> all()
commands/ commands/
mod.rs pub fn all() mod.rs pub fn all()
<name>.rs <name>.rs§Why a hand-maintained all() and not real auto-detection
Rust has no runtime module reflection: nothing can walk commands/ at
startup and find the structs in it. The choices are a build script that
generates the registry, an inventory-style linker-section crate, or a
registry function the tool maintains. The registry function wins because
it stays readable and editable by hand — you can see every command the
app has in one place, reorder them, comment one out — and the scaffolder
keeps it up to date so the common path costs you nothing. The marker
comments are how it finds its insertion points; delete them and the tool
falls back to telling you the two lines to add.
Calling this a second time with a different name appends to the existing
mod.rs and touches neither main.rs nor the plugin’s lib.rs again.