Browse Source

Add global -f, -y and -I flags, rename file flag to output for downloads

timvisee 7 năm trước cách đây
mục cha
commit
e0e7d7d009

+ 1 - 1
cli/src/action/download.rs

@@ -35,7 +35,7 @@ impl<'a> Download<'a> {
         let file = RemoteFile::parse_url(url, None)?;
         let file = RemoteFile::parse_url(url, None)?;
 
 
         // Get the target file or directory
         // Get the target file or directory
-        let target = self.cmd.file();
+        let target = self.cmd.output();
 
 
         // Create a progress bar reporter
         // Create a progress bar reporter
         let bar = Arc::new(Mutex::new(ProgressBar::new_download()));
         let bar = Arc::new(Mutex::new(ProgressBar::new_download()));

+ 8 - 5
cli/src/cmd/cmd_download.rs

@@ -24,9 +24,12 @@ impl<'a: 'b, 'b> CmdDownload<'a> {
                 .help("The share URL")
                 .help("The share URL")
                 .required(true)
                 .required(true)
                 .multiple(false))
                 .multiple(false))
-            .arg(Arg::with_name("file")
-                .long("file")
-                .short("f")
+            .arg(Arg::with_name("output")
+                .long("output")
+                .short("o")
+                .alias("output-file")
+                .alias("out")
+                .alias("file")
                 .value_name("PATH")
                 .value_name("PATH")
                 .help("The output file or directory"))
                 .help("The output file or directory"))
             .arg(Arg::with_name("password")
             .arg(Arg::with_name("password")
@@ -80,8 +83,8 @@ impl<'a: 'b, 'b> CmdDownload<'a> {
     /// The target file or directory to download the file to.
     /// The target file or directory to download the file to.
     /// If a directory is given, the file name of the original uploaded file
     /// If a directory is given, the file name of the original uploaded file
     /// will be used.
     /// will be used.
-    pub fn file(&'a self) -> PathBuf {
-        self.matches.value_of("file")
+    pub fn output(&'a self) -> PathBuf {
+        self.matches.value_of("output")
             .map(|path| PathBuf::from(path))
             .map(|path| PathBuf::from(path))
             .unwrap_or(PathBuf::from("./"))
             .unwrap_or(PathBuf::from("./"))
     }
     }

+ 22 - 1
cli/src/cmd/handler.rs

@@ -1,4 +1,4 @@
-use super::clap::{App, ArgMatches};
+use super::clap::{App, AppSettings, Arg, ArgMatches};
 
 
 use app::*;
 use app::*;
 
 
@@ -22,6 +22,27 @@ impl<'a: 'b, 'b> Handler<'a> {
             .version(APP_VERSION)
             .version(APP_VERSION)
             .author(APP_AUTHOR)
             .author(APP_AUTHOR)
             .about(APP_ABOUT)
             .about(APP_ABOUT)
+            .global_setting(AppSettings::GlobalVersion)
+            .global_setting(AppSettings::VersionlessSubcommands)
+            // TODO: enable below command when it doesn't break `p` anymore.
+            // .global_setting(AppSettings::InferSubcommands)
+            .arg(Arg::with_name("force")
+                .long("force")
+                .short("f")
+                .global(true)
+                .help("Force the action, ignore warnings"))
+            .arg(Arg::with_name("no-interact")
+                .long("no-interact")
+                .short("I")
+                .alias("no-interactive")
+                .global(true)
+                .help("Not interactive, do not prompt"))
+            .arg(Arg::with_name("yes")
+                .long("yes")
+                .short("y")
+                .visible_alias("assume-yes")
+                .global(true)
+                .help("Assume yes for prompts"))
             .subcommand(CmdDelete::build())
             .subcommand(CmdDelete::build())
             .subcommand(CmdDownload::build().display_order(2))
             .subcommand(CmdDownload::build().display_order(2))
             .subcommand(CmdInfo::build())
             .subcommand(CmdInfo::build())