Manually implement clap::Args for ExpirationArg.
This commit is contained in:
parent
f0e73deb7f
commit
c6eb28eb1b
@ -15,23 +15,8 @@ use clap::builder::Resettable;
|
|||||||
use crate::cli::types::Time;
|
use crate::cli::types::Time;
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
#[derive(clap::Args, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ExpirationArg {
|
pub struct ExpirationArg {
|
||||||
#[clap(
|
|
||||||
long = "expiration",
|
|
||||||
allow_hyphen_values = true,
|
|
||||||
value_name = "EXPIRATION",
|
|
||||||
default_value_t = Expiration::Never,
|
|
||||||
help =
|
|
||||||
"Sets the expiration time",
|
|
||||||
long_help = "\
|
|
||||||
Sets the expiration time.
|
|
||||||
|
|
||||||
EXPIRATION is either an ISO 8601 formatted date with an optional time \
|
|
||||||
or a custom duration. A duration takes the form `N[ymwds]`, where the \
|
|
||||||
letters stand for years, months, weeks, days, and seconds, respectively. \
|
|
||||||
Alternatively, the keyword `never` does not set an expiration time.",
|
|
||||||
)]
|
|
||||||
expiration: Expiration,
|
expiration: Expiration,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +35,54 @@ impl ExpirationArg {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl clap::Args for ExpirationArg {
|
||||||
|
fn augment_args(cmd: clap::Command) -> clap::Command {
|
||||||
|
cmd.arg(
|
||||||
|
clap::Arg::new("expiration")
|
||||||
|
.long("expiration")
|
||||||
|
.allow_hyphen_values(true)
|
||||||
|
.value_name("EXPIRATION")
|
||||||
|
.value_parser(Expiration::new)
|
||||||
|
.default_value(Expiration::Never)
|
||||||
|
.help("Sets the expiration time")
|
||||||
|
.long_help("\
|
||||||
|
Sets the expiration time
|
||||||
|
|
||||||
|
EXPIRATION is either an ISO 8601 formatted date with an optional time \
|
||||||
|
or a custom duration. A duration takes the form `N[ymwds]`, where the \
|
||||||
|
letters stand for years, months, weeks, days, and seconds, respectively. \
|
||||||
|
Alternatively, the keyword `never` does not set an expiration time.")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn augment_args_for_update(cmd: clap::Command) -> clap::Command {
|
||||||
|
Self::augment_args(cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl clap::FromArgMatches for ExpirationArg {
|
||||||
|
fn update_from_arg_matches(&mut self, matches: &clap::ArgMatches)
|
||||||
|
-> clap::error::Result<()>
|
||||||
|
{
|
||||||
|
if let Some(v) = matches.get_one::<Expiration>("expiration") {
|
||||||
|
self.expiration = v.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_arg_matches(matches: &clap::ArgMatches)
|
||||||
|
-> clap::error::Result<Self>
|
||||||
|
{
|
||||||
|
let mut expiration = ExpirationArg {
|
||||||
|
expiration: Expiration::Never,
|
||||||
|
};
|
||||||
|
|
||||||
|
expiration.update_from_arg_matches(matches)?;
|
||||||
|
Ok(expiration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Expiration information
|
/// Expiration information
|
||||||
///
|
///
|
||||||
/// This enum tracks expiry information either in the form of a timestamp or
|
/// This enum tracks expiry information either in the form of a timestamp or
|
||||||
|
Loading…
x
Reference in New Issue
Block a user