Remove CLI help dots, update .gitignore, remove .rs file

This commit is contained in:
timvisee 2018-04-18 21:53:14 +02:00
parent e88198053f
commit 69797a3119
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
9 changed files with 8 additions and 107 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
.*.sw[po] .*.sw[po]
/target target/
**/*.rs.bk **/*.rs.bk
.idea/ .idea/

View file

@ -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<CmdPassword<'a>> {
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<String> {
// 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")
}
}

View file

@ -8,7 +8,7 @@ pub struct CmdDelete;
impl CmdDelete { impl CmdDelete {
pub fn build<'a, 'b>() -> App<'a, 'b> { pub fn build<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("delete") SubCommand::with_name("delete")
.about("Delete a shared file.") .about("Delete a shared file")
.visible_alias("del") .visible_alias("del")
.alias("r") .alias("r")
.alias("rem") .alias("rem")

View file

@ -8,7 +8,7 @@ pub struct CmdDownload;
impl CmdDownload { impl CmdDownload {
pub fn build<'a, 'b>() -> App<'a, 'b> { pub fn build<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("download") SubCommand::with_name("download")
.about("Download files.") .about("Download files")
.visible_alias("d") .visible_alias("d")
.visible_alias("down") .visible_alias("down")
.arg(ArgUrl::build()) .arg(ArgUrl::build())

View file

@ -8,7 +8,7 @@ pub struct CmdExists;
impl CmdExists { impl CmdExists {
pub fn build<'a, 'b>() -> App<'a, 'b> { pub fn build<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("exists") SubCommand::with_name("exists")
.about("Check whether a remote file exists.") .about("Check whether a remote file exists")
.visible_alias("e") .visible_alias("e")
.alias("exist") .alias("exist")
.arg(ArgUrl::build()) .arg(ArgUrl::build())

View file

@ -8,7 +8,7 @@ pub struct CmdInfo;
impl CmdInfo { impl CmdInfo {
pub fn build<'a, 'b>() -> App<'a, 'b> { pub fn build<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("info") SubCommand::with_name("info")
.about("Fetch info about a shared file.") .about("Fetch info about a shared file")
.visible_alias("i") .visible_alias("i")
.alias("information") .alias("information")
.arg(ArgUrl::build()) .arg(ArgUrl::build())

View file

@ -13,7 +13,7 @@ impl CmdParams {
]; ];
SubCommand::with_name("parameters") SubCommand::with_name("parameters")
.about("Change parameters of a shared file.") .about("Change parameters of a shared file")
.visible_alias("params") .visible_alias("params")
.alias("par") .alias("par")
.alias("param") .alias("param")

View file

@ -8,7 +8,7 @@ pub struct CmdPassword;
impl CmdPassword { impl CmdPassword {
pub fn build<'a, 'b>() -> App<'a, 'b> { pub fn build<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("password") 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("pass")
.visible_alias("p") .visible_alias("p")
.arg(ArgUrl::build()) .arg(ArgUrl::build())

View file

@ -13,7 +13,7 @@ impl CmdUpload {
// Build the subcommand // Build the subcommand
#[allow(unused_mut)] #[allow(unused_mut)]
let mut cmd = SubCommand::with_name("upload") let mut cmd = SubCommand::with_name("upload")
.about("Upload files.") .about("Upload files")
.visible_alias("u") .visible_alias("u")
.visible_alias("up") .visible_alias("up")
.arg(Arg::with_name("FILE") .arg(Arg::with_name("FILE")