Add validators schema and code templates
This commit is contained in:
45
src/templates/rust.handlebars
Normal file
45
src/templates/rust.handlebars
Normal file
@@ -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<Command>,
|
||||
}
|
||||
|
||||
#[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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user