summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2022-07-19 15:59:25 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2022-07-20 10:22:25 +0200
commit47b69c5d64a2fb783dca1a26b820dfa705ac393b (patch)
tree1fa273f3d3406c639f8f22740e193c69ad615deb
parent7d76a57c6b372b0549aa7f8750c32cb812ec2fcc (diff)
sq: Derive subcommand display order from fields.
- This is more intuitive instead of fiddling with display_order numbers. - Allows iterating over the subcommands in the order they are displayed.
-rw-r--r--sq/sq-usage.md16
-rw-r--r--sq/src/sq_cli.rs97
2 files changed, 46 insertions, 67 deletions
diff --git a/sq/sq-usage.md b/sq/sq-usage.md
index 5f0cf511..de8fab08 100644
--- a/sq/sq-usage.md
+++ b/sq/sq-usage.md
@@ -24,14 +24,6 @@ OPTIONS:
-f, --force
Overwrites existing files
- -h, --help
- Print help information
-
- --known-notation <NOTATION>
- Adds NOTATION to the list of known notations. This is used when
- validating signatures. Signatures that have unknown notations with
- the critical bit set are considered invalid.
-
--output-format <FORMAT>
Produces output in FORMAT, if possible
@@ -44,6 +36,14 @@ OPTIONS:
[env: SQ_OUTPUT_VERSION=]
+ --known-notation <NOTATION>
+ Adds NOTATION to the list of known notations. This is used when
+ validating signatures. Signatures that have unknown notations with
+ the critical bit set are considered invalid.
+
+ -h, --help
+ Print help information
+
-V, --version
Print version information
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index f477e9d9..dcf122bc 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -21,15 +21,6 @@ pub fn build() -> Command<'static> {
}
/// Defines the CLI.
-///
-/// The order of top-level subcommands is:
-///
-/// - Encryption & decryption (1xx)
-/// - Signing & verification (2xx)
-/// - Key & cert-ring management (3xx)
-/// - Key discovery & networking (4xx)
-/// - Armor (5xx)
-/// - Inspection & packet manipulation (6xx)
#[derive(Parser, Debug)]
#[clap(
name = "sq",
@@ -51,6 +42,7 @@ to refer to OpenPGP keys that do contain secrets.
subcommand_required = true,
arg_required_else_help = true,
disable_colored_help = true,
+ setting(clap::AppSettings::DeriveDisplayOrder),
)]
pub struct SqCommand {
#[clap(
@@ -91,24 +83,40 @@ pub struct SqCommand {
pub subcommand: SqSubcommands,
}
+/// The order of top-level subcommands is:
+///
+/// - Encryption & decryption
+/// - Signing & verification
+/// - Key & cert-ring management
+/// - Key discovery & networking
+/// - Armor
+/// - Inspection & packet manipulation
+///
+/// The order is derived from the order of variants in this enum.
#[derive(Debug, Subcommand)]
pub enum SqSubcommands {
- Armor(ArmorCommand),
- Dearmor(DearmorCommand),
+ Encrypt(EncryptCommand),
+ Decrypt(DecryptCommand),
+
Sign(SignCommand),
Verify(VerifyCommand),
- Wkd(WkdCommand),
- Keyserver(KeyserverCommand),
- Revoke(RevokeCommand),
- Packet(PacketCommand),
- Certify(CertifyCommand),
- Keyring(KeyringCommand),
+
Key(KeyCommand),
- Inspect(InspectCommand),
- Encrypt(EncryptCommand),
- Decrypt(DecryptCommand),
+ Keyring(KeyringCommand),
+ Certify(CertifyCommand),
+
#[cfg(feature = "autocrypt")]
Autocrypt(autocrypt::AutocryptCommand),
+ Keyserver(KeyserverCommand),
+ Wkd(WkdCommand),
+
+ Armor(ArmorCommand),
+ Dearmor(DearmorCommand),
+
+ Inspect(InspectCommand),
+ Packet(PacketCommand),
+
+ Revoke(RevokeCommand),
}
use chrono::{offset::Utc, DateTime};
@@ -193,7 +201,6 @@ pub struct IoArgs {
#[derive(Parser, Debug)]
#[clap(
name = "armor",
- display_order = 500,
about = "Converts binary to ASCII",
long_about =
"Converts binary to ASCII
@@ -257,8 +264,8 @@ impl From<CliArmorKind> for Option<OpenPGPArmorKind> {
}
#[derive(Parser, Debug)]
-#[clap(name = "dearmor", display_order(510))]
#[clap(
+ name = "dearmor",
about = "Converts ASCII to binary",
long_about =
"Converts ASCII to binary
@@ -289,7 +296,6 @@ pub struct DearmorCommand {
#[derive(Parser, Debug)]
#[clap(
name = "verify",
- display_order(210),
about = "Verifies signed messages or detached signatures",
long_about = "Verifies signed messages or detached signatures
@@ -360,7 +366,6 @@ pub struct VerifyCommand {
#[derive(Parser, Debug)]
#[clap(
name = "sign",
- display_order(200),
about = "Signs messages or data files",
long_about =
"Signs messages or data files
@@ -477,7 +482,6 @@ pub struct SignCommand {
#[derive(Parser, Debug)]
#[clap(
name = "packet",
- display_order = 610,
about = "Low-level packet manipulation",
long_about =
"Low-level packet manipulation
@@ -490,6 +494,7 @@ as a learning tool.
",
subcommand_required = true,
arg_required_else_help = true,
+ setting(clap::AppSettings::DeriveDisplayOrder),
)]
pub struct PacketCommand {
#[clap(subcommand)]
@@ -506,7 +511,6 @@ pub enum PacketSubcommands {
#[derive(Debug, Args)]
#[clap(
- display_order = 100,
about = "Lists packets",
long_about =
"
@@ -560,7 +564,6 @@ pub struct PacketDumpCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 200,
about = "Unwraps an encryption container",
long_about = "Unwraps an encryption container
@@ -611,7 +614,6 @@ pub struct PacketDecryptCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 300,
about = "Splits a message into packets",
long_about = "Splits a message into packets
@@ -643,7 +645,6 @@ pub struct PacketSplitCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 310,
about = "Joins packets split across files",
long_about = "Joins packets split across files
@@ -719,7 +720,6 @@ impl From<PacketKind> for Option<openpgp::armor::Kind> {
#[derive(Parser, Debug)]
#[clap(
name = "revoke",
- display_order = 700,
about = "Generates revocation certificates",
long_about = "Generates revocation certificates.
@@ -756,6 +756,7 @@ $ sq revoke userid --time 20220101 --certificate juliet.pgp \\
",
subcommand_required = true,
arg_required_else_help = true,
+ setting(clap::AppSettings::DeriveDisplayOrder),
)]
pub struct RevokeCommand {
#[clap(subcommand)]
@@ -771,7 +772,6 @@ pub enum RevokeSubcommands {
#[derive(Debug, Args)]
#[clap(
- display_order = 100,
about = "Revoke a certificate",
long_about =
"Revokes a certificate
@@ -919,7 +919,6 @@ impl From<RevocationReason> for OpenPGPRevocationReason {
#[derive(Debug, Args)]
#[clap(
- display_order = 105,
about = "Revoke a subkey",
long_about =
"Revokes a subkey
@@ -1053,7 +1052,6 @@ certificate's creation time",
#[derive(Debug, Args)]
#[clap(
- display_order = 110,
about = "Revoke a User ID",
long_about =
"Revokes a User ID
@@ -1191,7 +1189,6 @@ impl From<UseridRevocationReason> for OpenPGPRevocationReason {
#[derive(Parser, Debug)]
#[clap(
name = "certify",
- display_order = 320,
about = "Certifies a User ID for a Certificate",
long_about =
"Certifies a User ID for a Certificate
@@ -1396,7 +1393,6 @@ $ sq certify --time 20130721T0550+0200 neal.pgp ada.pgp ada
#[derive(Parser, Debug)]
#[clap(
name = "keyring",
- display_order = 310,
about = "Manages collections of keys or certs",
long_about =
"Manages collections of keys or certs
@@ -1411,6 +1407,7 @@ terms keys and certs interchangeably.
",
subcommand_required = true,
arg_required_else_help = true,
+ setting(clap::AppSettings::DeriveDisplayOrder),
)]
pub struct KeyringCommand {
#[clap(subcommand)]
@@ -1419,16 +1416,15 @@ pub struct KeyringCommand {
#[derive(Debug, Subcommand)]
pub enum KeyringSubcommands {
- Filter(KeyringFilterCommand),
- Join(KeyringJoinCommand),
- Merge(KeyringMergeCommand),
List(KeyringListCommand),
Split(KeyringSplitCommand),
+ Join(KeyringJoinCommand),
+ Merge(KeyringMergeCommand),
+ Filter(KeyringFilterCommand),
}
#[derive(Debug, Args)]
#[clap(
- display_order = 600,
about = "Joins keys into a keyring applying a filter",
long_about =
"Joins keys into a keyring applying a filter
@@ -1553,7 +1549,6 @@ pub struct KeyringFilterCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 300,
about = "Joins keys or keyrings into a single keyring",
long_about =
"Joins keys or keyrings into a single keyring
@@ -1590,7 +1585,6 @@ pub struct KeyringJoinCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 350,
about = "Merges keys or keyrings into a single keyring",
long_about =
"Merges keys or keyrings into a single keyring
@@ -1631,7 +1625,6 @@ pub struct KeyringMergeCommand {
#[derive(Debug, Args)]
#[clap(
about = "Lists keys in a keyring",
- display_order = 100,
long_about =
"Lists keys in a keyring
@@ -1666,7 +1659,6 @@ pub struct KeyringListCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 200,
about = "Splits a keyring into individual keys",
long_about =
"Splits a keyring into individual keys
@@ -1711,7 +1703,6 @@ pub struct KeyringSplitCommand {
#[derive(Parser, Debug)]
#[clap(
name = "key",
- display_order = 300,
about = "Manages keys",
long_about =
"Manages keys
@@ -1726,6 +1717,7 @@ operations on certificates.
",
subcommand_required = true,
arg_required_else_help = true,
+ setting(clap::AppSettings::DeriveDisplayOrder),
)]
pub struct KeyCommand {
#[clap(subcommand)]
@@ -1739,13 +1731,12 @@ pub enum KeySubcommands {
#[clap(subcommand)]
Userid(KeyUseridCommand),
ExtractCert(KeyExtractCertCommand),
- Adopt(KeyAdoptCommand),
AttestCertifications(KeyAttestCertificationsCommand),
+ Adopt(KeyAdoptCommand),
}
#[derive(Debug, Args)]
#[clap(
- display_order = 100,
about = "Generates a new key",
long_about =
"Generates a new key
@@ -1923,7 +1914,6 @@ pub enum KeyEncryptPurpose {
#[derive(Debug, Args)]
#[clap(
name = "password",
- display_order = 105,
about = "Changes password protecting secrets",
long_about =
"Changes password protecting secrets
@@ -1966,7 +1956,6 @@ pub struct KeyPasswordCommand {
#[derive(Debug, Args)]
#[clap(
name = "extract-cert",
- display_order = 110,
about = "Converts a key to a cert",
long_about =
"Converts a key to a cert
@@ -1999,7 +1988,6 @@ pub struct KeyExtractCertCommand {
#[derive(Debug, Subcommand)]
#[clap(
name = "userid",
- display_order = 105,
about = "Manages User IDs",
long_about =
"Manages User IDs
@@ -2008,6 +1996,7 @@ Add User IDs to, or strip User IDs from a key.
",
subcommand_required = true,
arg_required_else_help = true,
+ setting(clap::AppSettings::DeriveDisplayOrder),
)]
pub enum KeyUseridCommand {
Add(KeyUseridAddCommand),
@@ -2016,7 +2005,6 @@ pub enum KeyUseridCommand {
#[derive(Debug, Args)]
#[clap(
- display_order = 10,
about = "Adds a User ID",
long_about =
"Adds a User ID
@@ -2083,7 +2071,6 @@ $ sq key userid add --userid \"Juliet\" --creation-time 20210628T1137+0200 \\
#[derive(Debug, Args)]
#[clap(
- display_order = 20,
about = "Strips a User ID",
long_about =
"Strips a User ID
@@ -2142,7 +2129,6 @@ User ID."
#[derive(Debug, Args)]
#[clap(
name = "adopt",
- display_order = 800,
about = "Binds keys from one certificate to another",
long_about =
"Binds keys from one certificate to another
@@ -2207,7 +2193,6 @@ pub struct KeyAdoptCommand {
#[derive(Debug, Args)]
#[clap(
name = "attest-certifications",
- display_order = 200,
about = "Attests to third-party certifications",
long_about =
"
@@ -2270,7 +2255,6 @@ pub struct KeyAttestCertificationsCommand {
#[derive(Parser, Debug)]
#[clap(
name = "wkd",
- display_order = 420,
about = "Interacts with Web Key Directories",
subcommand_required = true,
arg_required_else_help = true,
@@ -2408,7 +2392,6 @@ pub struct WkdGenerateCommand {
#[derive(Parser, Debug)]
#[clap(
name = "keyserver",
- display_order = 410,
about = "Interacts with keyservers",
subcommand_required = true,
arg_required_else_help = true,
@@ -2498,7 +2481,6 @@ pub struct KeyserverSendCommand {
#[derive(Parser, Debug)]
#[clap(
name = "inspect",
- display_order(600),
about = "Inspects data, like file(1)",
long_about =
"Inspects data, like file(1)
@@ -2541,7 +2523,6 @@ pub struct InspectCommand {
#[derive(Parser, Debug)]
#[clap(
name = "encrypt",
- display_order = 100,
about = "Encrypts a message",
long_about =
"Encrypts a message
@@ -2665,7 +2646,6 @@ pub enum EncryptCompressionMode {
#[derive(Parser, Debug)]
#[clap(
name = "decrypt",
- display_order = 110,
about = "Decrypts a message",
long_about =
"Decrypts a message
@@ -2835,7 +2815,6 @@ pub mod autocrypt {
#[derive(Parser, Debug)]
#[clap(
name = "autocrypt",
- display_order(400),
about = "Communicates certificates using Autocrypt",
long_about =
"Communicates certificates using Autocrypt