summaryrefslogtreecommitdiffstats
path: root/sq
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2022-06-02 13:19:53 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2022-06-08 14:49:43 +0200
commitb7c5c9416d2a7ee8fdc6dab1df8f10c061ea029f (patch)
tree19e3caa68cde2f9cac71122dbcd3124c55cf7751 /sq
parent0fb10b9fb5297a2c941a70bbd899b2dbc8c926df (diff)
sq: Adapt sign command to clap3's derive style.
- This is part of the effort of moving to clap3's derive API and profit from the added type safety.
Diffstat (limited to 'sq')
-rw-r--r--sq/src/sq.rs37
-rw-r--r--sq/src/sq_cli.rs3
2 files changed, 22 insertions, 18 deletions
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index eba6a771..f08513c0 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -488,18 +488,20 @@ fn main() -> Result<()> {
})?;
},
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");
- let binary = m.is_present("binary");
- let append = m.is_present("append");
- let notarize = m.is_present("notarize");
- let private_key_store = m.value_of("private-key-store");
- let secrets = m.values_of("secret-key-file")
- .map(load_certs)
- .unwrap_or_else(|| Ok(vec![]))?;
- let time = if let Some(time) = m.value_of("time") {
- Some(parse_iso8601(time, chrono::NaiveTime::from_hms(0, 0, 0))
+ use clap::FromArgMatches;
+ let command = sq_cli::SignCommand::from_arg_matches(m)?;
+
+ let mut input = open_or_stdin(command.input.as_deref())?;
+ let output = command.output.as_deref();
+ let detached = command.detached;
+ let binary = command.binary;
+ let append = command.append;
+ let notarize = command.notarize;
+ let private_key_store = command.private_key_store.as_deref();
+ let secrets =
+ load_certs(command.secret_key_file.iter().map(|s| s.as_ref()))?;
+ let time = if let Some(time) = command.time {
+ Some(parse_iso8601(&time, chrono::NaiveTime::from_hms(0, 0, 0))
.context(format!("Bad value passed to --time: {:?}",
time))?.into())
} else {
@@ -508,7 +510,8 @@ fn main() -> Result<()> {
// Each --notation takes two values. The iterator
// returns them one at a time, however.
let mut notations: Vec<(bool, NotationData)> = Vec::new();
- if let Some(mut n) = m.values_of("notation") {
+ if let Some(n) = command.notation {
+ let mut n = n.iter();
while let Some(name) = n.next() {
let value = n.next().unwrap();
@@ -516,7 +519,7 @@ fn main() -> Result<()> {
if let Some(name) = name.strip_prefix('!') {
(true, name)
} else {
- (false, name)
+ (false, name.as_str())
};
notations.push(
@@ -527,12 +530,12 @@ fn main() -> Result<()> {
}
}
- if let Some(merge) = m.value_of("merge") {
+ if let Some(merge) = command.merge {
let output = config.create_or_stdout_pgp(output, binary,
armor::Kind::Message)?;
- let mut input2 = open_or_stdin(Some(merge))?;
+ let mut input2 = open_or_stdin(Some(&merge))?;
commands::merge_signatures(&mut input, &mut input2, output)?;
- } else if m.is_present("clearsign") {
+ } else if command.clearsign {
let output = config.create_or_stdout_safe(output)?;
commands::sign::clearsign(config, private_key_store, input, output, secrets,
time, &notations)?;
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 8395c947..06e830a3 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -2028,5 +2028,6 @@ pub struct SignCommand {
)]
// TODO: Is there a better way to express that one notation consists of two arguments, and
// there may be multiple notations? Like something like Vec<(String, String)>.
- pub notation: Vec<String>,
+ // TODO: Also, no need for the Option
+ pub notation: Option<Vec<String>>,
}