From 4a9ffe85e16b753ed4bbe1c68994b69d6d13a1a1 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 07:11:05 +0000 Subject: [PATCH] Add validators schema and code templates --- src/templates/rust.handlebars | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/templates/rust.handlebars 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"); + } + } +}