From a6f7dc1528d093225b09ce423cfdb1539fe9764d Mon Sep 17 00:00:00 2001 From: meisZWFLZ Date: Tue, 21 May 2024 21:48:01 -0700 Subject: [PATCH] feat: :sparkles: write some more example cli code get some experience with rust / clap --- packages/lemlink/src/main.rs | 52 +++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/packages/lemlink/src/main.rs b/packages/lemlink/src/main.rs index a675854..8723914 100644 --- a/packages/lemlink/src/main.rs +++ b/packages/lemlink/src/main.rs @@ -1,22 +1,62 @@ use clap::Parser as _; #[derive(clap::Parser)] -struct Args { + +struct TopLevelArgs { #[clap(subcommand)] command: Command, } #[derive(clap::Subcommand)] +enum ConductorSubcommand { + CreateTemplate(CreateTemplateArgs), +} + +#[derive(clap::Parser, Debug)] +#[command(hide = true)] +struct CreateTemplateArgs { + #[arg()] + path: String, + #[arg()] + name: String, + #[arg()] + version: String, + #[clap(long)] + system: Vec, + #[clap(long)] + user: Vec, + #[clap(long, value_enum, value_name = "TARGET", num_args = 1 )] + target: CreateTemplateTarget, + #[clap(long, value_name = "KERNEL_VERSION")] + kernels: Option, + #[clap(long, value_name = "PATH")] + destination: Option, +} + +#[derive(clap::ValueEnum, Copy, Clone, Debug, PartialEq, Eq)] +enum CreateTemplateTarget { + V5, + Cortex, +} + +#[derive(clap::Subcommand)] +#[command(infer_subcommands = true)] enum Command { - Example, + Conductor { + #[clap(subcommand)] + command: ConductorSubcommand, + }, + } fn main() { - let args = Args::parse(); + let args = TopLevelArgs::parse(); match args.command { - Command::Example => { - println!("Hello, world!"); - } + Command::Conductor{command} => match command { + ConductorSubcommand::CreateTemplate(template_args) => { + println!("{:?}", template_args); + } + }, } }