use clap::ArgMatches;
use ffsend_api::api::Version as ApiVersion;
use ffsend_api::url::Url;
use super::Matcher;
use crate::cmd::{
arg::{ArgDownloadLimit, ArgOwner, ArgUrl, CmdArgOption},
matcher::MainMatcher,
};
pub struct ParamsMatcher<'a> {
matches: &'a ArgMatches<'a>,
}
impl<'a: 'b, 'b> ParamsMatcher<'a> {
pub fn url(&'a self) -> Url {
ArgUrl::value(self.matches)
}
pub fn owner(&'a self) -> Option<String> {
ArgOwner::value(self.matches).map(|token| token.to_owned())
}
pub fn download_limit(
&'a self,
main_matcher: &MainMatcher,
api_version: ApiVersion,
auth: bool,
) -> Option<usize> {
ArgDownloadLimit::value_checked(self.matches, main_matcher, api_version, auth)
}
}
impl<'a> Matcher<'a> for ParamsMatcher<'a> {
fn with(matches: &'a ArgMatches) -> Option<Self> {
matches
.subcommand_matches("parameters")
.map(|matches| ParamsMatcher { matches })
}
}