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.
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};
/// The sub command name.
const CMD_NAME: &'static str = "upload";
use app::SEND_DEF_HOST;
/// The upload command.
pub struct CmdUpload<'a> {
@ -11,27 +10,40 @@ pub struct CmdUpload<'a> {
impl<'a: 'b, 'b> CmdUpload<'a> {
/// Build the sub command definition.
pub fn build<'y, 'z>() -> App<'y, 'z> {
SubCommand::with_name(CMD_NAME)
SubCommand::with_name("upload")
.about("Upload files")
.visible_alias("u")
.visible_alias("up")
.arg(
Arg::with_name("FILE")
.help("The file to upload")
.required(true)
.multiple(false)
)
.arg(Arg::with_name("FILE")
.help("The file to upload")
.required(true)
.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.
pub fn parse(parent: &'a ArgMatches<'a>) -> Option<CmdUpload<'a>> {
parent.subcommand_matches(CMD_NAME)
parent.subcommand_matches("upload")
.map(|matches| CmdUpload { matches })
}
/// Get the selected file to upload.
pub fn file(&'a self) -> &'a str {
self.matches.value_of("FILE")
.expect("please specify a file to upload")
.expect("no file specified to upload")
}
}