From f1c30786d703bd3becf5dd66f027925e2201153d Mon Sep 17 00:00:00 2001 From: franzi Date: Tue, 10 Dec 2024 15:43:57 +0100 Subject: [PATCH] Refactor packet and keyring files in /cli to new example framework. - No content changes. --- src/cli/keyring.rs | 253 ++++++++++++++++---------------------- src/cli/packet.rs | 182 ++++++++++++--------------- src/cli/packet/armor.rs | 44 +++---- src/cli/packet/dearmor.rs | 17 ++- 4 files changed, 208 insertions(+), 288 deletions(-) diff --git a/src/cli/keyring.rs b/src/cli/keyring.rs index d44296b2..0e46e8b4 100644 --- a/src/cli/keyring.rs +++ b/src/cli/keyring.rs @@ -190,90 +190,70 @@ a certificate.", const FILTER_EXAMPLES: Actions = Actions { actions: &[ - Action::Setup(Setup { - command: &[ - "sq", "keyring", "merge", - "--output=certs.pgp", - "bob.pgp", "romeo.pgp", - ], - }), + Action::setup().command(&[ + "sq", "keyring", "merge", + "--output=certs.pgp", + "bob.pgp", "romeo.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Convert all keys to certificates (i.e. remove any secret key material).", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--to-cert", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Convert all keys to certificates (i.e. remove any secret key material).", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--to-cert", + "certs.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Get all certificates with a user ID on example.org.", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--domain=example.org", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Get all certificates with a user ID on example.org.", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--domain=example.org", + "certs.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Get all certificates with a user ID on example.org or example.net.", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--domain=example.org", - "--domain=example.net", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Get all certificates with a user ID on example.org or example.net.", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--domain=example.org", + "--domain=example.net", + "certs.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Get all certificates with a name user ID matching Romeo.", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--name=Romeo", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Get all certificates with a name user ID matching Romeo.", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--name=Romeo", + "certs.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Get all certificates with a name user ID matching Romeo on example.org.", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--domain=example.org", - "certs.pgp", - "|", "sq", "keyring", "filter", - "--experimental", - "--name=Romeo", - ], - hide: &[], - }), + Action::example().comment( + "Get all certificates with a name user ID matching Romeo on example.org.", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--domain=example.org", + "certs.pgp", + "|", "sq", "keyring", "filter", + "--experimental", + "--name=Romeo", + ]).build(), - Action::Example(Example { - comment: "\ -Get all certificates with a user ID on example.org, pruning other user IDs.", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--domain=example.org", - "--prune-certs", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Get all certificates with a user ID on example.org, pruning other user IDs.", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--domain=example.org", + "--prune-certs", + "certs.pgp", + ]).build(), ], }; test_examples!(sq_keyring_filter, FILTER_EXAMPLES); @@ -305,22 +285,18 @@ pub struct MergeCommand { const MERGE_EXAMPLES: Actions = Actions { actions: &[ - Action::Setup(Setup { - command: &[ - "sq", "packet", "dearmor", - "--output=bob-updates.pgp", - "bob.pgp", - ], - }), + Action::setup().command(&[ + "sq", "packet", "dearmor", + "--output=bob-updates.pgp", + "bob.pgp", + ]).build(), - Action::Example(Example { - comment: "Merge certificate updates.", - command: &[ - "sq", "keyring", "merge", - "bob.pgp", "bob-updates.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Merge certificate updates.", + ).command(&[ + "sq", "keyring", "merge", + "bob.pgp", "bob-updates.pgp", + ]).build(), ], }; test_examples!(sq_keyring_merge, MERGE_EXAMPLES); @@ -357,35 +333,28 @@ standard policy.", const LIST_EXAMPLES: Actions = Actions { actions: &[ - Action::Setup(Setup { - command: &[ - "sq", "keyring", "merge", - "--output=certs.pgp", - "bob.pgp", "romeo.pgp", - ], - }), + Action::setup().command(&[ + "sq", "keyring", "merge", + "--output=certs.pgp", + "bob.pgp", "romeo.pgp", + ]).build(), - Action::Example(Example { - comment: "List all certificates.", - command: &[ - "sq", "keyring", "list", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "List all certificates.", + ).command(&[ + "sq", "keyring", "list", + "certs.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -List all certificates with a user ID on example.org.", - command: &[ - "sq", "keyring", "filter", - "--experimental", - "--domain=example.org", - "certs.pgp", - "|", "sq", "keyring", "list", - ], - hide: &[], - }), + Action::example().comment( + "List all certificates with a user ID on example.org.", + ).command(&[ + "sq", "keyring", "filter", + "--experimental", + "--domain=example.org", + "certs.pgp", + "|", "sq", "keyring", "list", + ]).build(), ], }; test_examples!(sq_keyring_list, LIST_EXAMPLES); @@ -421,34 +390,26 @@ pub struct SplitCommand { const SPLIT_EXAMPLES: Actions = Actions { actions: &[ - Action::Setup(Setup { - command: &[ - "sq", "keyring", "merge", - "--output=certs.pgp", - "bob.pgp", "romeo.pgp", - ], - }), + Action::setup().command(&[ + "sq", "keyring", "merge", + "--output=certs.pgp", + "bob.pgp", "romeo.pgp", + ]).build(), - Action::Example(Example { - comment: "Split all certificates.", - command: &[ - "sq", "keyring", "split", - "certs.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Split all certificates.", + ).command(&[ + "sq", "keyring", "split", + "certs.pgp", + ]).build(), - - Action::Example(Example { - comment: "\ -Split all certificates, merging them first to avoid duplicates.", - command: &[ - "sq", "keyring", "merge", - "certs.pgp", - "|", "sq", "keyring", "split", - ], - hide: &[], - }), + Action::example().comment( + "Split all certificates, merging them first to avoid duplicates.", + ).command(&[ + "sq", "keyring", "merge", + "certs.pgp", + "|", "sq", "keyring", "split", + ]).build(), ], }; test_examples!(sq_keyring_split, SPLIT_EXAMPLES); diff --git a/src/cli/packet.rs b/src/cli/packet.rs index ca73a8ac..2bbc0563 100644 --- a/src/cli/packet.rs +++ b/src/cli/packet.rs @@ -116,47 +116,35 @@ pub struct DumpCommand { const DUMP_EXAMPLES: Actions = Actions { actions: &[ - Action::Example(Example { - comment: "\ -Print the packets of a certificate.", - command: &[ - "sq", "packet", "dump", - "juliet.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Print the packets of a certificate.", + ).command(&[ + "sq", "packet", "dump", + "juliet.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Print the packets including cryptographic artifacts of a certificate.", - command: &[ - "sq", "packet", "dump", - "--mpis", "juliet.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Print the packets including cryptographic artifacts of a certificate.", + ).command(&[ + "sq", "packet", "dump", + "--mpis", "juliet.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Print the packets including a dump of every byte of a certificate.", - command: &[ - "sq", "packet", "dump", - "--hex", "juliet.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Print the packets including a dump of every byte of a certificate.", + ).command(&[ + "sq", "packet", "dump", + "--hex", "juliet.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Prints the packets of an encrypted message, decrypting it using a \ -secret key file.", - command: &[ - "sq", "packet", "dump", - "--recipient-file", "bob-secret.pgp", - "message.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Prints the packets of an encrypted message, decrypting it using a \ + secret key file.", + ).command(&[ + "sq", "packet", "dump", + "--recipient-file", "bob-secret.pgp", + "message.pgp", + ]).build(), ], }; test_examples!(sq_packet_dump, DUMP_EXAMPLES); @@ -232,16 +220,13 @@ pub struct DecryptCommand { const DECRYPT_EXAMPLES: Actions = Actions { actions: &[ - Action::Example(Example { - comment: "\ -Unwrap the encryption revealing the signed message.", - command: &[ - "sq", "packet", "decrypt", - "--recipient-file", "bob-secret.pgp", - "message.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Unwrap the encryption revealing the signed message.", + ).command(&[ + "sq", "packet", "decrypt", + "--recipient-file", "bob-secret.pgp", + "message.pgp", + ]).build(), ], }; test_examples!(sq_packet_decrypt, DECRYPT_EXAMPLES); @@ -307,42 +292,33 @@ a human-readable packet type with dashes ('-'). const SPLIT_EXAMPLES: Actions = Actions { actions: &[ - Action::Example(Example { - comment: "\ -Split a certificate into individual packets printed to stdout.", - command: &[ - "sq", "packet", "split", - "--output=-", - "juliet.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Split a certificate into individual packets printed to stdout.", + ).command(&[ + "sq", "packet", "split", + "--output=-", + "juliet.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Split a inline-signed message into individual packets written to \ -individual files with the prefix 'packet'.", - command: &[ - "sq", "packet", "split", - "--output-prefix", "packet", - "document.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Split a inline-signed message into individual packets written to \ + individual files with the prefix 'packet'.", + ).command(&[ + "sq", "packet", "split", + "--output-prefix", "packet", + "document.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Then reassemble the message, transforming it into an old-style \ -signed message with a prefix signature.", - command: &[ - "sq", "packet", "join", - "--output", "prefix-signature.pgp", - "--label", "message", - "packet-2-Signature-Packet", - "packet-1-Literal-Data-Packet", - ], - hide: &[], - }), + Action::example().comment( + "Then reassemble the message, transforming it into an old-style \ + signed message with a prefix signature.", + ).command(&[ + "sq", "packet", "join", + "--output", "prefix-signature.pgp", + "--label", "message", + "packet-2-Signature-Packet", + "packet-1-Literal-Data-Packet", + ]).build(), ], }; test_examples!(sq_packet_split, SPLIT_EXAMPLES); @@ -388,31 +364,25 @@ pub struct JoinCommand { const JOIN_EXAMPLES: Actions = Actions { actions: &[ - Action::Example(Example { - comment: "\ -Split a inline-signed message into individual packets written to \ -individual files with the prefix 'packet'.", - command: &[ - "sq", "packet", "split", - "--output-prefix", "packet", - "document.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Split a inline-signed message into individual packets written to \ + individual files with the prefix 'packet'.", + ).command(&[ + "sq", "packet", "split", + "--output-prefix", "packet", + "document.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Then reassemble the message, transforming it into an old-style \ -signed message with a prefix signature.", - command: &[ - "sq", "packet", "join", - "--output", "prefix-signature.pgp", - "--label", "message", - "packet-2-Signature-Packet", - "packet-1-Literal-Data-Packet", - ], - hide: &[], - }), + Action::example().comment( + "Then reassemble the message, transforming it into an old-style \ + signed message with a prefix signature.", + ).command(&[ + "sq", "packet", "join", + "--output", "prefix-signature.pgp", + "--label", "message", + "packet-2-Signature-Packet", + "packet-1-Literal-Data-Packet", + ]).build(), ], }; test_examples!(sq_packet_join, JOIN_EXAMPLES); diff --git a/src/cli/packet/armor.rs b/src/cli/packet/armor.rs index 740e7306..5d063970 100644 --- a/src/cli/packet/armor.rs +++ b/src/cli/packet/armor.rs @@ -50,35 +50,27 @@ pub struct Command { const EXAMPLES: Actions = Actions { actions: &[ - Action::Setup(Setup { - command: &[ - "sq", "packet", "dearmor", - "--output=message.bin", - "message.pgp", - ], - }), + Action::setup().command(&[ + "sq", "packet", "dearmor", + "--output=message.bin", + "message.pgp", + ]).build(), - Action::Example(Example { - comment: "\ -Convert a binary OpenPGP message to an ASCII armored OpenPGP message.", - command: &[ - "sq", "packet", "armor", - "message.bin", - ], - hide: &[], - }), + Action::example().comment( + "Convert a binary OpenPGP message to an ASCII armored OpenPGP message.", + ).command(&[ + "sq", "packet", "armor", + "message.bin", + ]).build(), - Action::Example(Example { - comment: "\ -Convert a binary OpenPGP message to an ASCII armored OpenPGP message + Action::example().comment( + "Convert a binary OpenPGP message to an ASCII armored OpenPGP message explicitly choosing the armor label.", - command: &[ - "sq", "packet", "armor", - "--label=message", - "message.bin", - ], - hide: &[], - }), + ).command(&[ + "sq", "packet", "armor", + "--label=message", + "message.bin", + ]).build(), ], }; test_examples!(sq_packet_armor, EXAMPLES); diff --git a/src/cli/packet/dearmor.rs b/src/cli/packet/dearmor.rs index 7b0adb22..6a90f42e 100644 --- a/src/cli/packet/dearmor.rs +++ b/src/cli/packet/dearmor.rs @@ -40,16 +40,13 @@ pub struct Command { const EXAMPLES: Actions = Actions { actions: &[ - Action::Example(Example { - comment: "\ -Convert an ASCII armored OpenPGP message to a binary OpenPGP message.", - command: &[ - "sq", "packet", "dearmor", - "--output=message.bin", - "message.pgp", - ], - hide: &[], - }), + Action::example().comment( + "Convert an ASCII armored OpenPGP message to a binary OpenPGP message.", + ).command(&[ + "sq", "packet", "dearmor", + "--output=message.bin", + "message.pgp", + ]).build(), ], }; test_examples!(sq_packet_dearmor, EXAMPLES);