diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2022-05-06 17:57:06 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2022-05-16 14:23:08 +0200 |
commit | f17ada2baf2866e90ac1f9d68309ed9b8d8347f8 (patch) | |
tree | 3d3e47c2f9eb69cb41a56ce91fcadf42ed008f96 /sq/src/sq.rs | |
parent | e41ce7b791031bf40d0035673fd2f32b2a2a029c (diff) |
sq: Port command line handling from clap 2 to 3.
Change sq command line handling from using clap version 2 to version 3,
and adapt to all the breaking changes.
Clap version 3 is a major new version with a number of breaking
changes. It also adds functionality to allow a structopt style
declarative way of defining command line syntax. We want to use that,
but first we need to port the old "builder style" of defining the
command line syntax to clap version 3. The change to use the "derive
style" comes later.
The semantics of clap version 2's .multiple function were hard to
understand and it was replaced with .multiple_occurences. Care was taken
to preserve the original intention regarding an argument's number of
occurrences and number of values.
There are some changes to help output (in src/sq-usage.rs). These are
mostly from upstream changes and we think the differences are minor so
we are okay with following upstream's lead. In summary: FLAGS and
OPTIONS are merged into just OPTIONS; the layout of subcommand lists are
a little different (split into two lines); there is no "[--]" before
filename arguments anymore; default and allowed values for options are
on a separate line now; --version isn't repeated for every subcommand
anymore; help is listed for each subcommand separately.
In addition, we will help clap upstream fix a problem where the
help output doesn't have a "..." to indicate that an option may be used
several times.
Further, upstream has changed --help text to be of the form "Print
help", when it earlier was "Prints help". We will change our own help
texts to follow suite in a future commit. We don't do it in this commit,
to avoid making an even larger diff.
By default, clap v3 now colors its help output. However, this does not
support custom sections like our examples. Clap is tracking this as
https://github.com/clap-rs/clap/issues/3108. In the meantime, disable
colors.
Diffstat (limited to 'sq/src/sq.rs')
-rw-r--r-- | sq/src/sq.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/sq/src/sq.rs b/sq/src/sq.rs index c3831535..308e49f2 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -409,7 +409,7 @@ fn main() -> Result<()> { }; match matches.subcommand() { - ("decrypt", Some(m)) => { + Some(("decrypt", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let mut output = config.create_or_stdout_safe(m.value_of("output"))?; @@ -441,7 +441,7 @@ fn main() -> Result<()> { m.is_present("dump-session-key"), m.is_present("dump"), m.is_present("hex"))?; }, - ("encrypt", Some(m)) => { + Some(("encrypt", m)) => { let recipients = m.values_of("recipients-cert-file") .map(load_certs) .unwrap_or_else(|| Ok(vec![]))?; @@ -485,7 +485,7 @@ fn main() -> Result<()> { use_expired_subkey: m.is_present("use-expired-subkey"), })?; }, - ("sign", Some(m)) => { + Some(("sign", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let output = m.value_of("output"); let detached = m.is_present("detached"); @@ -550,7 +550,7 @@ fn main() -> Result<()> { })?; } }, - ("verify", Some(m)) => { + Some(("verify", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let mut output = config.create_or_stdout_safe(m.value_of("output"))?; @@ -569,7 +569,7 @@ fn main() -> Result<()> { &mut output, signatures, certs)?; }, - ("armor", Some(m)) => { + Some(("armor", m)) => { let input = open_or_stdin(m.value_of("input"))?; let mut want_kind = parse_armor_kind(m.value_of("kind")); @@ -619,7 +619,7 @@ fn main() -> Result<()> { } output.finalize()?; }, - ("dearmor", Some(m)) => { + Some(("dearmor", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let mut output = config.create_or_stdout_safe(m.value_of("output"))?; @@ -627,19 +627,19 @@ fn main() -> Result<()> { io::copy(&mut filter, &mut output)?; }, #[cfg(feature = "autocrypt")] - ("autocrypt", Some(m)) => commands::autocrypt::dispatch(config, m)?, + Some(("autocrypt", m)) => commands::autocrypt::dispatch(config, m)?, - ("inspect", Some(m)) => { + Some(("inspect", m)) => { // sq inspect does not have --output, but commands::inspect does. // Work around this mismatch by always creating a stdout output. let mut output = config.create_or_stdout_unsafe(None)?; commands::inspect(m, policy, &mut output)?; }, - ("keyring", Some(m)) => commands::keyring::dispatch(config, m)?, + Some(("keyring", m)) => commands::keyring::dispatch(config, m)?, - ("packet", Some(m)) => match m.subcommand() { - ("dump", Some(m)) => { + Some(("packet", m)) => match m.subcommand() { + Some(("dump", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let mut output = config.create_or_stdout_unsafe(m.value_of("output"))?; @@ -655,7 +655,7 @@ fn main() -> Result<()> { session_key.as_ref(), width)?; }, - ("decrypt", Some(m)) => { + Some(("decrypt", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let mut output = config.create_or_stdout_pgp(m.value_of("output"), @@ -671,7 +671,7 @@ fn main() -> Result<()> { output.finalize()?; }, - ("split", Some(m)) => { + Some(("split", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let prefix = // The prefix is either specified explicitly... @@ -689,20 +689,20 @@ fn main() -> Result<()> { + "-"); commands::split(&mut input, &prefix)?; }, - ("join", Some(m)) => commands::join(config, m)?, + Some(("join", m)) => commands::join(config, m)?, _ => unreachable!(), }, - ("keyserver", Some(m)) => + Some(("keyserver", m)) => commands::net::dispatch_keyserver(config, m)?, - ("key", Some(m)) => commands::key::dispatch(config, m)?, + Some(("key", m)) => commands::key::dispatch(config, m)?, - ("revoke", Some(m)) => commands::revoke::dispatch(config, m)?, + Some(("revoke", m)) => commands::revoke::dispatch(config, m)?, - ("wkd", Some(m)) => commands::net::dispatch_wkd(config, m)?, + Some(("wkd", m)) => commands::net::dispatch_wkd(config, m)?, - ("certify", Some(m)) => { + Some(("certify", m)) => { commands::certify::certify(config, m)?; }, |