Debian Codegraph @

src/cli/inspect.rs

raw
1 //! Command-line parser for `sq inspect`.
2
3 use clap::Parser;
4
5 use super::types::ClapData;
6 use super::types::FileOrStdin;
7 use super::types::cert_designator::*;
8
9 use crate::cli::examples;
10 use examples::Action;
11 use examples::Actions;
12
13 const INSPECT_EXAMPLES: Actions = Actions {
14 actions: &[
15 Action::example().comment(
16 "Inspect a certificate.",
17 ).command(&[
18 "sq", "inspect", "juliet.pgp",
19 ]).build(),
20
21 Action::example().comment(
22 "Show how the certificate looked on July 21, 2013.",
23 ).command(&[
24 "sq", "inspect", "--time", "20130721", "juliet.pgp",
25 ]).build(),
26
27 Action::example().comment(
28 "Inspect an encrypted message.",
29 ).command(&[
30 "sq", "inspect", "message.pgp",
31 ]).build(),
32
33 Action::example().comment(
34 "Inspect a detached signature.",
35 ).command(&[
36 "sq", "inspect", "document.sig",
37 ]).build(),
38 ],
39 };
40 test_examples!(sq_inspect, INSPECT_EXAMPLES);
41
42 #[derive(Parser, Debug)]
43 #[clap(
44 name = "inspect",
45 about = "Inspect data, like file(1)",
46 long_about =
47 "Inspect data, like file(1)
48
49 It is often difficult to tell from cursory inspection using cat(1) or \
50 file(1) what kind of OpenPGP one is looking at. This subcommand \
51 inspects the data and provides a meaningful human-readable description \
52 of it.
53
54 `sq inspect` respects the reference time set by the top-level \
55 `--time` argument. It uses the reference time when determining what \
56 binding signatures are active.
57 ",
58 after_help = INSPECT_EXAMPLES,
59 )]
60 pub struct Command {
61 #[clap(
62 default_value_t = FileOrStdin::default(),
63 help = FileOrStdin::HELP_OPTIONAL,
64 value_name = FileOrStdin::VALUE_NAME,
65 conflicts_with_all = ["cert-file", "cert", "cert-userid", "cert-email", "cert-domain", "cert-grep"],
66 )]
67 pub input: FileOrStdin,
68
69 #[command(flatten)]
70 pub certs: CertDesignators<FileCertUserIDEmailDomainGrepArgs,
71 CertPrefix,
72 OptionalValue,
73 ToInspectDoc>,
74
75 #[clap(
76 long = "certifications",
77 help = "Print third-party certifications",
78 )]
79 pub certifications: bool,
80
81 #[clap(
82 long = "dump-bad-signatures",
83 help = "Dump signatures that are definitively bad",
84 )]
85 pub dump_bad_signatures: bool,
86 }
87
88 /// Documentation for the cert designators for `--inspect`.
89 pub struct ToInspectDoc {}
90
91 impl AdditionalDocs for ToInspectDoc {
92 fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
93 let help = help.replace("Use", "Inspect");
94 match arg {
95 "cert" | "file" => help,
96 _ => format!(
97 "{} (note: User IDs are not authenticated)",
98 help),
99 }.into()
100 }
101 }