Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
feat: ✨ write some more example cli code
Browse files Browse the repository at this point in the history
get some experience with rust / clap
  • Loading branch information
meisZWFLZ committed May 22, 2024
1 parent 6a6fb53 commit a6f7dc1
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions packages/lemlink/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
#[clap(long)]
user: Vec<String>,
#[clap(long, value_enum, value_name = "TARGET", num_args = 1 )]
target: CreateTemplateTarget,
#[clap(long, value_name = "KERNEL_VERSION")]
kernels: Option<String>,
#[clap(long, value_name = "PATH")]
destination: Option<String>,
}

#[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);
}
},
}
}

0 comments on commit a6f7dc1

Please sign in to comment.