This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ write some more example cli code
get some experience with rust / clap
- Loading branch information
Showing
1 changed file
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}, | ||
} | ||
} |