use {
crate::*,
argh::FromArgs,
};
#[derive(Debug, FromArgs)]
pub struct Args {
#[argh(switch, short = 'v')]
pub version: bool,
#[argh(subcommand)]
pub command: Option<ArgsCommand>,
#[argh(switch)]
pub verbose: bool,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
pub enum ArgsCommand {
Add(AddCommand),
Remove(RemoveCommand),
Update(UpdateCommand),
Check(CheckCommand),
List(ListCommand),
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "check")]
pub struct CheckCommand {
#[argh(positional)]
pub user: UserRef,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "add")]
pub struct AddCommand {
#[argh(positional)]
pub user: UserRef,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "remove")]
pub struct RemoveCommand {
#[argh(positional)]
pub user: UserRef,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "update")]
pub struct UpdateCommand {}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "list")]
pub struct ListCommand {}
#[derive(Debug, Clone, Copy, Default)]
pub struct BoolArg(Option<bool>);
impl BoolArg {
pub fn value(self) -> Option<bool> {
self.0
}
}
impl argh::FromArgValue for BoolArg {
fn from_arg_value(value: &str) -> std::result::Result<Self, String> {
match value.to_lowercase().as_ref() {
"auto" => Ok(BoolArg(None)),
"yes" => Ok(BoolArg(Some(true))),
"no" => Ok(BoolArg(Some(false))),
_ => Err(format!("Illegal value: {:?}", value)),
}
}
}