Debian Codegraph @

src/cli/key/expire.rs

raw
1 //! Command-line parser for `sq key expire`.
2
3 use clap::Args;
4
5 use crate::cli::types::ClapData;
6 use crate::cli::types::ExpirationArg;
7 use crate::cli::types::FileOrStdout;
8
9 use crate::cli::examples::*;
10 use crate::cli::types::cert_designator::*;
11
12 const EXAMPLES: Actions = Actions {
13 actions: &[
14 Action::setup().command(&[
15 "sq", "key", "import",
16 "alice-secret.pgp",
17 ]).build(),
18
19 Action::example().comment(
20 "Change Alice's certificate to expire in a year."
21 ).command(&[
22 "sq", "key", "expire", "--expiration", "1y",
23 "--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
24 ]).build(),
25
26 Action::example().comment(
27 "Change Alice's certificate to never expire."
28 ).command(&[
29 "sq", "key", "expire", "--expiration", "never",
30 "--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0",
31 ]).build(),
32 ],
33 };
34
35 test_examples!(sq_key_expire, EXAMPLES);
36
37 #[derive(Debug, Args)]
38 #[clap(
39 name = "expire",
40 about = "Change a certificate's expiration time",
41 long_about =
42 "Change a certificate's expiration time
43
44 This subcommand changes a certificate's expiration time. To change \
45 the expiration time of an individual subkey, use the `sq key subkey \
46 expire` subcommand.
47 ",
48 after_help = EXAMPLES,
49 )]
50 #[clap(mut_arg("expiration", |arg| {
51 arg.required(true)
52 }))]
53 pub struct Command {
54 #[command(flatten)]
55 pub cert: CertDesignators<CertUserIDEmailFileArgs,
56 CertPrefix,
57 OneValueAndFileRequiresOutput,
58 KeyExpireDoc>,
59
60 #[clap(
61 help = FileOrStdout::HELP_OPTIONAL,
62 long,
63 value_name = FileOrStdout::VALUE_NAME,
64 )]
65 pub output: Option<FileOrStdout>,
66
67 #[clap(flatten)]
68 pub expiration: ExpirationArg,
69 }
70
71 /// Documentation for the cert designators for the key expire.
72 pub struct KeyExpireDoc {}
73
74 impl AdditionalDocs for KeyExpireDoc {
75 fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr {
76 match arg {
77 "file" =>
78 "Change the expiration of the key \
79 read from PATH"
80 .into(),
81 _ => {
82 debug_assert!(help.starts_with("Use certificates"));
83 help.replace("Use certificates",
84 "Change the expiration of the key")
85 },
86 }.into()
87 }
88 }