summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2022-05-13 00:06:14 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2022-06-08 14:49:43 +0200
commit4944405da8e4e2e4fe924d6d08d400e2f2a7e6b5 (patch)
tree263912e7c9ca581d7d027aa1c47fc1cf2c8b6edb
parentb80127091f30ccf437267ac87a161d9042f808a9 (diff)
sq: Derive armor subcommand.
- This is part of the effort of moving to clap3's derive API and profit from the added type safety.
-rw-r--r--sq/src/sq_cli.rs90
1 files changed, 52 insertions, 38 deletions
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 218d83be..b907d6f5 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -1,6 +1,7 @@
/// Command-line parser for sq.
use clap::{Command, Arg, ArgGroup};
+use clap::{Parser, CommandFactory};
pub fn build() -> Command<'static> {
configure(Command::new("sq"),
@@ -368,43 +369,6 @@ signatures, consider using sequoia-sqv.
.help("Verifies signatures with CERT"))
)
- .subcommand(Command::new("armor")
- .display_order(500)
- .about("Converts binary to ASCII")
- .long_about(
-"Converts binary to ASCII
-
-To make encrypted data easier to handle and transport, OpenPGP data
-can be transformed to an ASCII representation called ASCII Armor. sq
-emits armored data by default, but this subcommand can be used to
-convert existing OpenPGP data to its ASCII-encoded representation.
-
-The converse operation is \"sq dearmor\".
-")
- .after_help(
-"EXAMPLES:
-
-# Convert a binary certificate to ASCII
-$ sq armor binary-juliet.pgp
-
-# Convert a binary message to ASCII
-$ sq armor binary-message.pgp
-")
- .arg(Arg::new("input")
- .value_name("FILE")
- .help("Reads from FILE or stdin if omitted"))
- .arg(Arg::new("output")
- .short('o').long("output").value_name("FILE")
- .help("Writes to FILE or stdout if omitted"))
- .arg(Arg::new("kind")
- .long("label").value_name("LABEL")
- .possible_values(&["auto", "message",
- "cert", "key", "sig",
- "file"])
- .default_value("auto")
- .help("Selects the kind of armor header"))
- )
-
.subcommand(Command::new("dearmor")
.display_order(510)
.about("Converts ASCII to binary")
@@ -1924,7 +1888,57 @@ $ sq autocrypt encode-sender --prefer-encrypt mutual juliet.pgp
attribute"))
)
)
- };
+ }
+ .subcommand(ArmorCommand::command());
app
}
+
+// TODO: convert possible values to enum
+// TODO?: Option<_> conflicts with default value
+// TODO: Use PathBuf as input type for more type safety? Investigate conversion
+// TODO: use indoc to transparently (de-)indent static strings
+#[derive(Parser, Debug)]
+#[clap(
+ name = "armor",
+ display_order = 500,
+ about = "Converts binary to ASCII",
+ long_about =
+"Converts binary to ASCII
+
+To make encrypted data easier to handle and transport, OpenPGP data
+can be transformed to an ASCII representation called ASCII Armor. sq
+emits armored data by default, but this subcommand can be used to
+convert existing OpenPGP data to its ASCII-encoded representation.
+
+The converse operation is \"sq dearmor\".
+",
+ after_help =
+"EXAMPLES:
+
+# Convert a binary certificate to ASCII
+$ sq armor binary-juliet.pgp
+
+# Convert a binary message to ASCII
+$ sq armor binary-message.pgp
+"
+ )]
+pub struct ArmorCommand {
+ #[clap(value_name = "FILE", help = "Reads from FILE or stdin if omitted")]
+ pub input: Option<String>,
+ #[clap(
+ short,
+ long,
+ value_name = "FILE",
+ help = "Writes to FILE or stdout if omitted"
+ )]
+ pub output: Option<String>,
+ #[clap(
+ long = "label",
+ value_name = "LABEL",
+ help = "Selects the kind of armor header",
+ possible_values = &["auto", "message", "cert", "key", "sig", "file"],
+ default_value = "auto",
+ )]
+ kind: String,
+}