Define some more upload command arguments

This commit is contained in:
timvisee 2018-03-08 19:26:11 +01:00
parent fb7fd69400
commit ae83064b36
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
2 changed files with 26 additions and 11 deletions

View file

@ -9,3 +9,6 @@ pub const APP_AUTHOR: &'static str = "Tim Visee <timvisee@gmail.com>";
/// Application about information. /// Application about information.
pub const APP_ABOUT: &'static str = "A simple Firefox Send CLI client."; pub const APP_ABOUT: &'static str = "A simple Firefox Send CLI client.";
/// The default Send host to use.
pub const SEND_DEF_HOST: &'static str = "localhost:8080";

View file

@ -1,7 +1,6 @@
use super::clap::{App, Arg, ArgMatches, SubCommand}; use super::clap::{App, Arg, ArgMatches, SubCommand};
/// The sub command name. use app::SEND_DEF_HOST;
const CMD_NAME: &'static str = "upload";
/// The upload command. /// The upload command.
pub struct CmdUpload<'a> { pub struct CmdUpload<'a> {
@ -11,27 +10,40 @@ pub struct CmdUpload<'a> {
impl<'a: 'b, 'b> CmdUpload<'a> { impl<'a: 'b, 'b> CmdUpload<'a> {
/// Build the sub command definition. /// Build the sub command definition.
pub fn build<'y, 'z>() -> App<'y, 'z> { pub fn build<'y, 'z>() -> App<'y, 'z> {
SubCommand::with_name(CMD_NAME) SubCommand::with_name("upload")
.about("Upload files") .about("Upload files")
.visible_alias("u") .visible_alias("u")
.visible_alias("up") .visible_alias("up")
.arg( .arg(Arg::with_name("FILE")
Arg::with_name("FILE") .help("The file to upload")
.help("The file to upload") .required(true)
.required(true) .multiple(false))
.multiple(false) .arg(Arg::with_name("host")
) .long("host")
.short("h")
.alias("server")
.value_name("URL")
.default_value(SEND_DEF_HOST)
.help("The Send host to upload to"))
.arg(Arg::with_name("open")
.long("open")
.short("o")
.help("Open the share link in your browser"))
.arg(Arg::with_name("c")
.long("copy")
.short("c")
.help("Copy the share link to your clipboard"))
} }
/// Parse CLI arguments, from the given parent command matches. /// Parse CLI arguments, from the given parent command matches.
pub fn parse(parent: &'a ArgMatches<'a>) -> Option<CmdUpload<'a>> { pub fn parse(parent: &'a ArgMatches<'a>) -> Option<CmdUpload<'a>> {
parent.subcommand_matches(CMD_NAME) parent.subcommand_matches("upload")
.map(|matches| CmdUpload { matches }) .map(|matches| CmdUpload { matches })
} }
/// Get the selected file to upload. /// Get the selected file to upload.
pub fn file(&'a self) -> &'a str { pub fn file(&'a self) -> &'a str {
self.matches.value_of("FILE") self.matches.value_of("FILE")
.expect("please specify a file to upload") .expect("no file specified to upload")
} }
} }