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/commands/net.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/commands/net.rs')
-rw-r--r-- | sq/src/commands/net.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/sq/src/commands/net.rs b/sq/src/commands/net.rs index 44046ee8..dbd33227 100644 --- a/sq/src/commands/net.rs +++ b/sq/src/commands/net.rs @@ -53,7 +53,7 @@ pub fn dispatch_keyserver(config: Config, m: &clap::ArgMatches) -> Result<()> { .build()?; match m.subcommand() { - ("get", Some(m)) => { + Some(("get", m)) => { let query = m.value_of("query").unwrap(); let handle = query.parse::<KeyHandle>(); @@ -83,7 +83,7 @@ pub fn dispatch_keyserver(config: Config, m: &clap::ArgMatches) -> Result<()> { or an email address: {:?}", query)); } }, - ("send", Some(m)) => { + Some(("send", m)) => { let mut input = open_or_stdin(m.value_of("input"))?; let cert = Cert::from_reader(&mut input). context("Malformed key")?; @@ -106,7 +106,7 @@ pub fn dispatch_wkd(config: Config, m: &clap::ArgMatches) -> Result<()> { .build()?; match m.subcommand() { - ("url", Some(m)) => { + Some(("url", m)) => { let email_address = m.value_of("input").unwrap(); let wkd_url = wkd::Url::from(email_address)?; // XXX: Add other subcomand to specify whether it should be @@ -114,7 +114,7 @@ pub fn dispatch_wkd(config: Config, m: &clap::ArgMatches) -> Result<()> { let url = wkd_url.to_url(None)?; println!("{}", url); }, - ("get", Some(m)) => { + Some(("get", m)) => { // Check that the policy allows https. network_policy.assert(net::Policy::Encrypted)?; @@ -137,7 +137,7 @@ pub fn dispatch_wkd(config: Config, m: &clap::ArgMatches) -> Result<()> { serialize_keyring(&mut output, &certs, m.is_present("binary"))?; }, - ("generate", Some(m)) => { + Some(("generate", m)) => { let domain = m.value_of("domain").unwrap(); let skip = m.is_present("skip"); let f = open_or_stdin(m.value_of("input"))?; |