sq/cli/packet/
armor.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use clap::Parser;

use crate::cli::examples::*;
use crate::cli::types::ArmorKind;
use crate::cli::types::ClapData;
use crate::cli::types::FileOrStdin;
use crate::cli::types::FileOrStdout;

// TODO?: Option<_> conflicts with default value
// TODO: use indoc to transparently (de-)indent static strings
#[derive(Parser, Debug)]
#[clap(
    name = "armor",
    about = "Convert binary to ASCII",
    long_about =
"Convert 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 packet dearmor`.
",
    after_help = EXAMPLES,
)]
pub struct Command {
    #[clap(
        default_value_t = FileOrStdin::default(),
        help = FileOrStdin::HELP_OPTIONAL,
        value_name = FileOrStdin::VALUE_NAME,
    )]
    pub input: FileOrStdin,
    #[clap(
        default_value_t = FileOrStdout::default(),
        help = FileOrStdout::HELP_OPTIONAL,
        long,
        value_name = FileOrStdout::VALUE_NAME,
    )]
    pub output: FileOrStdout,
    #[clap(
        long = "label",
        value_name = "LABEL",
        help = "Select the kind of armor header",
        default_value_t = ArmorKind::Auto,
        value_enum
    )]
    pub kind: ArmorKind,
}

const EXAMPLES: Actions = Actions {
    actions: &[
        Action::setup().command(&[
            "sq", "packet", "dearmor",
            "--output=message.bin",
            "message.pgp",
        ]).build(),

        Action::example().comment(
            "Convert a binary OpenPGP message to an ASCII armored OpenPGP message.",
        ).command(&[
            "sq", "packet", "armor",
            "message.bin",
        ]).build(),

        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",
        ]).build(),
    ],
};
test_examples!(sq_packet_armor, EXAMPLES);