diff --git a/.gitignore b/.gitignore index 4ad319d..5f36c07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .*.sw[po] -/target +target/ **/*.rs.bk .idea/ diff --git a/cli/src/cmd/cmd/.rs b/cli/src/cmd/cmd/.rs deleted file mode 100644 index d157704..0000000 --- a/cli/src/cmd/cmd/.rs +++ /dev/null @@ -1,99 +0,0 @@ -use ffsend_api::url::{ParseError, Url}; - -use clap::{App, Arg, ArgMatches, SubCommand}; -use rpassword::prompt_password_stderr; - -use util::quit_error_msg; - -/// The password command. -pub struct CmdPassword<'a> { - matches: &'a ArgMatches<'a>, -} - -impl<'a: 'b, 'b> CmdPassword<'a> { - /// Build the sub command definition. - pub fn build<'y, 'z>() -> App<'y, 'z> { - // Build the subcommand - let cmd = SubCommand::with_name("password") - .about("Change the password of a shared file.") - .visible_alias("p") - .visible_alias("pass") - .arg(Arg::with_name("URL") - .help("The share URL") - .required(true) - .multiple(false)) - .arg(Arg::with_name("password") - .long("password") - .short("p") - .alias("pass") - .value_name("PASSWORD") - .help("Specify a password, do not prompt")) - .arg(Arg::with_name("owner") - .long("owner") - .short("o") - .alias("own") - .alias("owner-token") - .alias("token") - .value_name("TOKEN") - .help("File owner token")); - - cmd - } - - /// Parse CLI arguments, from the given parent command matches. - pub fn parse(parent: &'a ArgMatches<'a>) -> Option> { - parent.subcommand_matches("password") - .map(|matches| CmdPassword { matches }) - } - - /// Get the file share URL. - /// - /// This method parses the URL into an `Url`. - /// If the given URL is invalid, - /// the program will quit with an error message. - pub fn url(&'a self) -> Url { - // Get the host - let url = self.matches.value_of("URL") - .expect("missing URL"); - - // Parse the URL - // TODO: improve these error messages - match Url::parse(url) { - Ok(url) => url, - Err(ParseError::EmptyHost) => - quit_error_msg("Emtpy host given"), - Err(ParseError::InvalidPort) => - quit_error_msg("Invalid host port"), - Err(ParseError::InvalidIpv4Address) => - quit_error_msg("Invalid IPv4 address in host"), - Err(ParseError::InvalidIpv6Address) => - quit_error_msg("Invalid IPv6 address in host"), - Err(ParseError::InvalidDomainCharacter) => - quit_error_msg("Host domains contains an invalid character"), - Err(ParseError::RelativeUrlWithoutBase) => - quit_error_msg("Host domain doesn't contain a host"), - _ => quit_error_msg("The given host is invalid"), - } - } - - /// Get the owner token. - pub fn owner(&'a self) -> Option { - // TODO: validate the owner token if set - self.matches.value_of("owner") - .map(|token| token.to_owned()) - } - - /// Get the password. - pub fn password(&'a self) -> String { - // Get the password from the arguments - if let Some(password) = self.matches.value_of("password") { - return password.into(); - } - - // Prompt for the password - // TODO: don't unwrap/expect - // TODO: create utility function for this - prompt_password_stderr("New password: ") - .expect("failed to read password from stdin") - } -} diff --git a/cli/src/cmd/cmd/delete.rs b/cli/src/cmd/cmd/delete.rs index f55c8d4..2c70055 100644 --- a/cli/src/cmd/cmd/delete.rs +++ b/cli/src/cmd/cmd/delete.rs @@ -8,7 +8,7 @@ pub struct CmdDelete; impl CmdDelete { pub fn build<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("delete") - .about("Delete a shared file.") + .about("Delete a shared file") .visible_alias("del") .alias("r") .alias("rem") diff --git a/cli/src/cmd/cmd/download.rs b/cli/src/cmd/cmd/download.rs index 15a5732..1b150b3 100644 --- a/cli/src/cmd/cmd/download.rs +++ b/cli/src/cmd/cmd/download.rs @@ -8,7 +8,7 @@ pub struct CmdDownload; impl CmdDownload { pub fn build<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("download") - .about("Download files.") + .about("Download files") .visible_alias("d") .visible_alias("down") .arg(ArgUrl::build()) diff --git a/cli/src/cmd/cmd/exists.rs b/cli/src/cmd/cmd/exists.rs index 52965bf..cfef750 100644 --- a/cli/src/cmd/cmd/exists.rs +++ b/cli/src/cmd/cmd/exists.rs @@ -8,7 +8,7 @@ pub struct CmdExists; impl CmdExists { pub fn build<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("exists") - .about("Check whether a remote file exists.") + .about("Check whether a remote file exists") .visible_alias("e") .alias("exist") .arg(ArgUrl::build()) diff --git a/cli/src/cmd/cmd/info.rs b/cli/src/cmd/cmd/info.rs index 45ae6bd..e706e4b 100644 --- a/cli/src/cmd/cmd/info.rs +++ b/cli/src/cmd/cmd/info.rs @@ -8,7 +8,7 @@ pub struct CmdInfo; impl CmdInfo { pub fn build<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("info") - .about("Fetch info about a shared file.") + .about("Fetch info about a shared file") .visible_alias("i") .alias("information") .arg(ArgUrl::build()) diff --git a/cli/src/cmd/cmd/params.rs b/cli/src/cmd/cmd/params.rs index dfad96d..b51bd33 100644 --- a/cli/src/cmd/cmd/params.rs +++ b/cli/src/cmd/cmd/params.rs @@ -13,7 +13,7 @@ impl CmdParams { ]; SubCommand::with_name("parameters") - .about("Change parameters of a shared file.") + .about("Change parameters of a shared file") .visible_alias("params") .alias("par") .alias("param") diff --git a/cli/src/cmd/cmd/password.rs b/cli/src/cmd/cmd/password.rs index 43b0aef..95743b5 100644 --- a/cli/src/cmd/cmd/password.rs +++ b/cli/src/cmd/cmd/password.rs @@ -8,7 +8,7 @@ pub struct CmdPassword; impl CmdPassword { pub fn build<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("password") - .about("Change the password of a shared file.") + .about("Change the password of a shared file") .visible_alias("pass") .visible_alias("p") .arg(ArgUrl::build()) diff --git a/cli/src/cmd/cmd/upload.rs b/cli/src/cmd/cmd/upload.rs index bdd5bbe..9b1e4ae 100644 --- a/cli/src/cmd/cmd/upload.rs +++ b/cli/src/cmd/cmd/upload.rs @@ -13,7 +13,7 @@ impl CmdUpload { // Build the subcommand #[allow(unused_mut)] let mut cmd = SubCommand::with_name("upload") - .about("Upload files.") + .about("Upload files") .visible_alias("u") .visible_alias("up") .arg(Arg::with_name("FILE")