Debian Codegraph @

src/cli/key/delete.rs

raw
1 //! Command-line parser for `sq key delete`.
2
3 use clap::Args;
4
5 use crate::cli::types::*;
6 use crate::cli::examples::*;
7 use crate::cli::types::cert_designator::*;
8
9 #[derive(Debug, Args)]
10 #[clap(
11 name = "delete",
12 about = "Delete a certificate's secret key material",
13 after_help = EXAMPLES,
14 )]
15 pub struct Command {
16 #[command(flatten)]
17 pub cert: CertDesignators<CertUserIDEmailFileArgs,
18 CertPrefix,
19 OneValueAndFileRequiresOutput,
20 DeleteKeyDoc>,
21
22 #[clap(
23 long,
24 value_name = FileOrStdout::VALUE_NAME,
25 conflicts_with = "cert",
26 help = "Write the stripped certificate to the specified file",
27 )]
28 pub output: Option<FileOrStdout>,
29 }
30
31 const EXAMPLES: Actions = Actions {
32 actions: &[
33 Action::setup().command(&[
34 "sq", "key", "import", "alice-secret.pgp",
35 ]).build(),
36
37 Action::example().comment("\
38 Delete any secret key associated with Alice's certificate."
39 ).command(&[
40 "sq", "key", "delete",
41 "--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
42 ]).build(),
43
44 Action::setup().command(&[
45 "sq", "key", "import", "alice-secret.pgp",
46 ]).build(),
47
48 Action::setup().command(&[
49 "sq", "pki", "link", "add",
50 "--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
51 "--userid=Alice <[email protected]>",
52 ]).build(),
53
54 Action::example().comment("\
55 Delete any secret key associated with Alice's certificate \
56 selected by user ID."
57 ).command(&[
58 "sq", "key", "delete",
59 "[email protected]",
60 ]).build(),
61 ]
62 };
63 test_examples!(sq_key_delete, EXAMPLES);
64
65 /// Documentation for the cert designators for the key delete.
66 pub struct DeleteKeyDoc {}
67
68 impl AdditionalDocs for DeleteKeyDoc {
69 fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
70 match arg {
71 "file" =>
72 "Delete the secret key material from the key read from PATH"
73 .into(),
74 _ => {
75 debug_assert!(help.starts_with("Use certificates"));
76 help.replace("Use certificates",
77 "Delete secret key material from the key")
78 },
79 }.into()
80 }
81 }