Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions argh/examples/completion_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct MyCmd {
enum Subcommands {
Completion(CompletionCmd),
DoThings(DoThingsCmd),
DoMoreThings(DoMoreThingsCmd),
}

#[derive(FromArgs, ArgsInfo)]
Expand All @@ -41,6 +42,39 @@ struct DoThingsCmd {
quick: bool,
}

#[derive(FromArgs, ArgsInfo)]
#[argh(subcommand)]
enum MoreThingsSubcommands {
ThingOne(ThingOneCommand),
ThingTwo(ThingTwoCommand),
}

#[derive(FromArgs, ArgsInfo)]
/// Do thing one.
#[argh(subcommand, name = "one")]
struct ThingOneCommand {
/// do it slowly
#[argh(switch, short = 's')]
slow: bool,
}

#[derive(FromArgs, ArgsInfo)]
/// Do thing two.
#[argh(subcommand, name = "two")]
struct ThingTwoCommand {
/// do it quickly
#[argh(switch, short = 'q')]
quick: bool,
}

#[derive(FromArgs, ArgsInfo)]
/// Do some more things.
#[argh(subcommand, name = "do-more-things")]
struct DoMoreThingsCmd {
#[argh(subcommand)]
cmd: MoreThingsSubcommands,
}

fn main() {
let args: MyCmd = argh::from_env();

Expand Down Expand Up @@ -74,5 +108,13 @@ fn main() {
Subcommands::DoThings(cmd) => {
println!("Doing {} things (quick: {})", cmd.count, cmd.quick);
}
Subcommands::DoMoreThings(cmd) => match cmd.cmd {
MoreThingsSubcommands::ThingOne(cmd) => {
println!("Doing more thing one (slow: {})", cmd.slow);
}
MoreThingsSubcommands::ThingTwo(cmd) => {
println!("Doing more thing two (quick: {})", cmd.quick);
}
},
}
}
2 changes: 1 addition & 1 deletion argh_complete/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ description = "Autocompletion generators for argh-based CLIs"
readme = "README.md"

[dependencies]
argh_shared = { version = "0.1.13", path = "../argh_shared" }
argh_shared.workspace = true
6 changes: 3 additions & 3 deletions argh_complete/src/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn generate_zsh_args(out: &mut String, prefix: &str, cmd: &CommandInfoWithArgs<'
if has_short && has_long {
let short = format!("-{}", flag.short.unwrap());
def.push_str(&format!(
"'({} {})'{{{},{}}}[{}]",
"'({} {})'{{{},{}}}'[{}]'",
short, flag.long, short, flag.long, desc
));
} else if has_long {
Expand Down Expand Up @@ -107,9 +107,9 @@ fn generate_zsh_args(out: &mut String, prefix: &str, cmd: &CommandInfoWithArgs<'
writeln!(out, "{} '{}:{}'", ind, subcmd.name, desc).unwrap();
}
writeln!(out, "{} )", ind).unwrap();
writeln!(out, "{} _describe -t commands '{} commands' subcommands", ind, cmd.name)
.unwrap();
writeln!(out, "{} if (( CURRENT == 1 )); then", ind).unwrap();
writeln!(out, "{} _describe -t commands '{} commands' subcommands", ind, cmd.name)
.unwrap();
writeln!(out, "{} return", ind).unwrap();
writeln!(out, "{} fi", ind).unwrap();
writeln!(out, "{} local cmd=$words[1]", ind).unwrap();
Expand Down