Skip to content

Commit

Permalink
Migrate to clap 4 for generating completions
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Aug 6, 2023
1 parent 3eb6194 commit 13aba14
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 69 deletions.
55 changes: 25 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ time = { version = ">=0.3.7, <0.3.24", optional = true } # time 0.3.24 has MSRV
zip = { version = "0.6.2", optional = true }

[dev-dependencies]
clap = "3.1"
clap_complete = "3.1"
clap = { version = "4", default-features = false }
clap_complete = "4"
flate2 = "1"
man = "0.3"

Expand Down
73 changes: 36 additions & 37 deletions rage/examples/generate-completions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{Arg, Command};
use clap::{Arg, ArgAction, Command};
use clap_complete::{generate, shells, Generator};
use std::fs::{create_dir_all, File};

Expand Down Expand Up @@ -46,53 +46,57 @@ fn generate_completions(mut app: Command, bin_name: &str) {
fn rage_completions() {
let app = Command::new("rage")
.arg(Arg::new("input"))
.arg(Arg::new("encrypt").short('e').long("encrypt"))
.arg(Arg::new("decrypt").short('d').long("decrypt"))
.arg(Arg::new("passphrase").short('p').long("passphrase"))
.arg(
Arg::new("max-work-factor")
.takes_value(true)
.long("max-work-factor"),
Arg::new("encrypt")
.short('e')
.long("encrypt")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("decrypt")
.short('d')
.long("decrypt")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("passphrase")
.short('p')
.long("passphrase")
.action(ArgAction::SetTrue),
)
.arg(Arg::new("max-work-factor").long("max-work-factor"))
.arg(
Arg::new("armor")
.short('a')
.long("armor")
.action(ArgAction::SetTrue),
)
.arg(Arg::new("armor").short('a').long("armor"))
.arg(
Arg::new("recipient")
.takes_value(true)
.multiple_occurrences(true)
.short('r')
.long("recipient"),
.long("recipient")
.action(ArgAction::Append),
)
.arg(
Arg::new("recipients-file")
.takes_value(true)
.multiple_occurrences(true)
.short('R')
.long("recipients-file"),
.long("recipients-file")
.action(ArgAction::Append),
)
.arg(
Arg::new("identity")
.takes_value(true)
.multiple_occurrences(true)
.short('i')
.long("identity"),
.long("identity")
.action(ArgAction::Append),
)
.arg(
Arg::new("output")
.takes_value(true)
.short('o')
.long("output"),
);
.arg(Arg::new("plugin-name").short('j'))
.arg(Arg::new("output").short('o').long("output"));

generate_completions(app, "rage");
}

fn rage_keygen_completions() {
let app = Command::new("rage-keygen").arg(
Arg::new("output")
.takes_value(true)
.short('o')
.long("output"),
);
let app = Command::new("rage-keygen").arg(Arg::new("output").short('o').long("output"));

generate_completions(app, "rage-keygen");
}
Expand All @@ -102,17 +106,12 @@ fn rage_mount_completions() {
.arg(Arg::new("filename"))
.arg(Arg::new("mountpoint"))
.arg(Arg::new("types").short('t').long("types"))
.arg(
Arg::new("max-work-factor")
.takes_value(true)
.long("max-work-factor"),
)
.arg(Arg::new("max-work-factor").long("max-work-factor"))
.arg(
Arg::new("identity")
.takes_value(true)
.multiple_occurrences(true)
.short('i')
.long("identity"),
.long("identity")
.action(ArgAction::Append),
);

generate_completions(app, "rage-mount");
Expand Down

0 comments on commit 13aba14

Please sign in to comment.