diff --git a/src/templates/rust.handlebars b/src/templates/rust.handlebars new file mode 100644 index 0000000..2fd6dd6 --- /dev/null +++ b/src/templates/rust.handlebars @@ -0,0 +1,45 @@ +use clap::{Parser, Subcommand}; + +/// {{spec.description}} +#[derive(Parser, Debug)] +#[command(name = "{{spec.name}}")] +#[command(version = "{{spec.version}}")] +#[command(author = "{{spec.author}}")] +#[command(about = "{{escape description}}")] +struct Args { + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand, Debug)] +enum Command { + {{#each spec.commands}} + /// {{escape description}} + {{pascalCase name}} { + {{#each arguments}} + /// {{escape description}} + {{#if variadic}}...{{/if}}{{rustArgType type required variadic}} {{camelCase name}}, + {{/each}} + {{#each options}} + /// {{escape description}} + #[arg(short, long{{#if default}}, default_value = "{{defaultValue}}"{{/if}})] + {{camelCase name}}: {{toRustType type}}, + {{/each}} + }, + {{/each}} +} + +fn main() { + let args = Args::parse(); + + match args.command { + {{#each spec.commands}} + Some(Command::{{pascalCase name}} { .. }) => { + println!("Running {{name}} command"); + } + {{/each}} + None => { + println!("Use --help to see available commands"); + } + } +}