Debian Codegraph @

src/cli/key/list.rs

raw
1 //! Command-line parser for `sq key list`.
2
3 use clap::Args;
4
5 use crate::cli::examples::*;
6 use crate::cli::types::cert_designator::*;
7
8 #[derive(Debug, Args)]
9 #[clap(
10 about = "List keys managed by the key store",
11 after_help = EXAMPLES,
12 )]
13 pub struct Command {
14 #[command(flatten)]
15 pub certs: CertDesignators<CertUserIDEmailDomainGrepArgs,
16 CertPrefix,
17 OptionalValue,
18 ListKeyDoc>,
19
20 #[clap(
21 value_name = "FINGERPRINT|KEYID|PATTERN",
22 help = "A pattern to filter the displayed certificates",
23 long_help = "\
24 A pattern to filter the displayed certificates
25
26 If the pattern appears to be a fingerprint or key ID, it is treated as \
27 if it were passed to `--cert`, and matches on the certificate's \
28 fingerprint. Otherwise, it is treated as if it were passed via \
29 `--cert-grep`, and matches on user IDs.
30 ",
31 conflicts_with_all = &["cert", "cert-userid", "cert-email",
32 "cert-domain", "cert-grep"],
33 )]
34 pub pattern: Option<String>,
35 }
36
37 const EXAMPLES: Actions = Actions {
38 actions: &[
39 Action::setup().command(&[
40 "sq", "key", "import", "alice-secret.pgp"
41 ]).build(),
42
43 Action::setup().command(&[
44 "sq", "pki", "link", "add",
45 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
46 "--userid=Alice <[email protected]>",
47 ]).build(),
48
49 Action::example().comment("\
50 List the keys managed by the keystore server."
51 ).command(&[
52 "sq", "key", "list",
53 ]).build(),
54
55 Action::example().comment("\
56 List the keys managed by the keystore server \
57 with a user ID in example.org."
58 ).command(&[
59 "sq", "key", "list",
60 "--cert-domain=example.org",
61 ]).build(),
62 ]
63 };
64 test_examples!(sq_key_list, EXAMPLES);
65
66 /// Documentation for the cert designators for the key list.
67 pub struct ListKeyDoc {}
68
69 impl AdditionalDocs for ListKeyDoc {
70 fn help(_: &'static str, help: &'static str) -> clap::builder::StyledStr {
71 debug_assert!(help.starts_with("Use certificates"));
72 help.replace("Use certificates", "List keys").into()
73 }
74 }