use 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,
#[argh(switch)]
pub no_save: bool,
#[argh(option, default = "30")]
pub max_rows: usize,
#[argh(option, default = "Default::default()")]
pub color: BoolArg,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
pub enum ArgsCommand {
Set(SetCommand),
Get(GetCommand),
Follow(FollowCommand),
Unfollow(UnfollowCommand),
Gaze(GazeCommand),
Extract(ExtractCommand),
Check(CheckCommand),
List(ListCommand),
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "set")]
pub struct SetCommand {
#[argh(positional)]
pub name: String,
#[argh(positional)]
pub value: String,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "get")]
pub struct GetCommand {
#[argh(positional)]
pub name: String,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "check")]
pub struct CheckCommand {
#[argh(positional)]
pub name: String,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "follow")]
pub struct FollowCommand {
#[argh(positional)]
pub name: String,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "unfollow")]
pub struct UnfollowCommand {
#[argh(positional)]
pub name: String,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "gaze")]
pub struct GazeCommand {}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "extract")]
pub struct ExtractCommand {
#[argh(positional)]
pub names: Vec<String>,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "list")]
pub struct ListCommand {
#[argh(positional)]
pub login: Option<String>,
}
#[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) -> 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)),
}
}
}