Debian Codegraph @

src/cli/packet/armor.rs

raw
1 use clap::Parser;
2
3 use crate::cli::examples::*;
4 use crate::cli::types::ArmorKind;
5 use crate::cli::types::ClapData;
6 use crate::cli::types::FileOrStdin;
7 use crate::cli::types::FileOrStdout;
8
9 // TODO?: Option<_> conflicts with default value
10 // TODO: use indoc to transparently (de-)indent static strings
11 #[derive(Parser, Debug)]
12 #[clap(
13 name = "armor",
14 about = "Convert binary to ASCII",
15 long_about =
16 "Convert binary to ASCII
17
18 To make encrypted data easier to handle and transport, OpenPGP data \
19 can be transformed to an ASCII representation called ASCII Armor. sq \
20 emits armored data by default, but this subcommand can be used to \
21 convert existing OpenPGP data to its ASCII-encoded representation.
22
23 The converse operation is `sq packet dearmor`.
24 ",
25 after_help = EXAMPLES,
26 )]
27 pub struct Command {
28 #[clap(
29 default_value_t = FileOrStdin::default(),
30 help = FileOrStdin::HELP_OPTIONAL,
31 value_name = FileOrStdin::VALUE_NAME,
32 )]
33 pub input: FileOrStdin,
34 #[clap(
35 default_value_t = FileOrStdout::default(),
36 help = FileOrStdout::HELP_OPTIONAL,
37 long,
38 value_name = FileOrStdout::VALUE_NAME,
39 )]
40 pub output: FileOrStdout,
41 #[clap(
42 long = "label",
43 value_name = "LABEL",
44 help = "Select the kind of armor header",
45 default_value_t = ArmorKind::Auto,
46 value_enum
47 )]
48 pub kind: ArmorKind,
49 }
50
51 const EXAMPLES: Actions = Actions {
52 actions: &[
53 Action::setup().command(&[
54 "sq", "packet", "dearmor",
55 "--output=message.bin",
56 "message.pgp",
57 ]).build(),
58
59 Action::example().comment(
60 "Convert a binary OpenPGP message to an ASCII armored OpenPGP message.",
61 ).command(&[
62 "sq", "packet", "armor",
63 "message.bin",
64 ]).build(),
65
66 Action::example().comment(
67 "Convert a binary OpenPGP message to an ASCII armored OpenPGP message
68 explicitly choosing the armor label.",
69 ).command(&[
70 "sq", "packet", "armor",
71 "--label=message",
72 "message.bin",
73 ]).build(),
74 ],
75 };
76 test_examples!(sq_packet_armor, EXAMPLES);