| 1 |
use clap::Args; |
| 2 |
|
| 3 |
use crate::cli::examples; |
| 4 |
use examples::Action; |
| 5 |
use examples::Actions; |
| 6 |
|
| 7 |
use crate::cli::types::CertDesignators; |
| 8 |
use crate::cli::types::ClapData; |
| 9 |
use crate::cli::types::ExpirationArg; |
| 10 |
use crate::cli::types::FileOrStdout; |
| 11 |
use crate::cli::types::KeyDesignators; |
| 12 |
use crate::cli::types::cert_designator; |
| 13 |
|
| 14 |
pub struct AdditionalDocs {} |
| 15 |
|
| 16 |
impl cert_designator::AdditionalDocs for AdditionalDocs { |
| 17 |
fn help(arg: &'static str, help: &'static str) -> clap::builder::StyledStr { |
| 18 |
match arg { |
| 19 |
"file" => |
| 20 |
"Change the expiration of the specified (sub)keys on the key \ |
| 21 |
read from PATH" |
| 22 |
.into(), |
| 23 |
_ => { |
| 24 |
debug_assert!(help.starts_with("Use certificates")); |
| 25 |
help.replace("Use certificates", |
| 26 |
"Change the expiration of the specified (sub)keys \ |
| 27 |
on the key") |
| 28 |
.into() |
| 29 |
}, |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
#[derive(Debug, Args)] |
| 35 |
#[clap( |
| 36 |
name = "expire", |
| 37 |
about = "Change a subkey's expiration time", |
| 38 |
long_about = "\ |
| 39 |
Change a subkey's expiration time |
| 40 |
|
| 41 |
This subcommand changes a key's expiration time. To change the \ |
| 42 |
expiration time of the certificate, use the `sq key expire` \ |
| 43 |
subcommand. |
| 44 |
|
| 45 |
Changing the expiration time of the primary key is equivalent to \ |
| 46 |
changing the certificate's expiration time. The expiration time \ |
| 47 |
of a subkey is bound by the expiration of the certificate. |
| 48 |
", |
| 49 |
after_help = EXAMPLES, |
| 50 |
)] |
| 51 |
#[clap(mut_arg("expiration", |arg| { |
| 52 |
arg.required(true) |
| 53 |
}))] |
| 54 |
pub struct Command { |
| 55 |
#[command(flatten)] |
| 56 |
pub cert: CertDesignators< |
| 57 |
cert_designator::CertUserIDEmailFileArgs, |
| 58 |
cert_designator::CertPrefix, |
| 59 |
cert_designator::OneValueAndFileRequiresOutput, |
| 60 |
AdditionalDocs>, |
| 61 |
|
| 62 |
#[command(flatten)] |
| 63 |
pub keys: KeyDesignators, |
| 64 |
|
| 65 |
#[command(flatten)] |
| 66 |
pub expiration: ExpirationArg, |
| 67 |
|
| 68 |
#[clap( |
| 69 |
long, |
| 70 |
value_name = FileOrStdout::VALUE_NAME, |
| 71 |
help = "Write to the specified FILE", |
| 72 |
long_help = "\ |
| 73 |
Write to the specified FILE |
| 74 |
|
| 75 |
If not specified, and the certificate was read from the certificate \ |
| 76 |
store, imports the modified certificate into the cert store. If not \ |
| 77 |
specified, and the certificate was read from a file, writes the \ |
| 78 |
modified certificate to stdout.", |
| 79 |
)] |
| 80 |
pub output: Option<FileOrStdout>, |
| 81 |
} |
| 82 |
|
| 83 |
const EXAMPLES: Actions = Actions { |
| 84 |
actions: &[ |
| 85 |
Action::setup().command(&[ |
| 86 |
"sq", "key", "import", "alice-secret.pgp" |
| 87 |
]).build(), |
| 88 |
|
| 89 |
Action::example().comment("\ |
| 90 |
Change Alice's authentication subkey to expire in 6 months." |
| 91 |
).command(&[ |
| 92 |
"sq", "key", "subkey", "expire", "--expiration", "6m", |
| 93 |
"--cert=EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 94 |
"--key=0D45C6A756A038670FDFD85CB1C82E8D27DB23A1", |
| 95 |
]).build(), |
| 96 |
], |
| 97 |
}; |
| 98 |
test_examples!(sq_key_subkey_expire, EXAMPLES); |