From ae83064b367d301fe8fe84aa805acd28b794bfe6 Mon Sep 17 00:00:00 2001 From: timvisee Date: Thu, 8 Mar 2018 19:26:11 +0100 Subject: [PATCH] Define some more upload command arguments --- src/app.rs | 3 +++ src/cmd/cmd_upload.rs | 34 +++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/app.rs b/src/app.rs index 102b7fe..7df52b5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -9,3 +9,6 @@ pub const APP_AUTHOR: &'static str = "Tim Visee "; /// 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"; diff --git a/src/cmd/cmd_upload.rs b/src/cmd/cmd_upload.rs index ac18667..59c5114 100644 --- a/src/cmd/cmd_upload.rs +++ b/src/cmd/cmd_upload.rs @@ -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> { - 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") } }