Sfoglia il codice sorgente

Define environment variables for CLI arguments

timvisee 7 anni fa
parent
commit
36c8c355d2

+ 12 - 0
REQUIREMENTS.md

@@ -9,3 +9,15 @@ toolchain.
   - Ubuntu package: `libssl-dev`
   - Ubuntu package: `libssl-dev`
 - On Linux, `xorg` development packages (for `clipboard` feature)
 - On Linux, `xorg` development packages (for `clipboard` feature)
   - Ubuntu package: `xorg-dev`
   - Ubuntu package: `xorg-dev`
+
+## Environment variables
+- `FFSEND_HOST`: upload host (string)
+- `FFSEND_FORCE`: upload host (present/boolean)
+- `FFSEND_NO_INTERACT`: upload host (present/boolean)
+- `FFSEND_YES`: upload host (present/boolean)
+- `FFSEND_HISTORY`: history file path (string)
+- `FFSEND_INCOGNITO`: incognito mode (present/boolean)
+- `FFSEND_OPEN`: open an uploaded file (present/boolean)
+- `FFSEND_ARCHIVE`: enable file archival (present/boolean)
+- `FFSEND_COPY`: copy share URL to clipboard (present/boolean)
+

+ 0 - 1
ROADMAP.md

@@ -7,7 +7,6 @@ Features:
 - Allow file/directory archiving on upload
 - Allow file/directory archiving on upload
 - Allow unarchiving on download 
 - Allow unarchiving on download 
 - Use clipboard through `xclip` on Linux if available for persistence
 - Use clipboard through `xclip` on Linux if available for persistence
-- Allow environment variable settings using `Arg.env(NAME)`
 - Write complete README
 - Write complete README
 - Polish command outputs, make it consistent (format, color)
 - Polish command outputs, make it consistent (format, color)
 - Automated releases through CI
 - Automated releases through CI

+ 4 - 2
cli/src/action/debug.rs

@@ -1,6 +1,6 @@
 use chrono::Duration;
 use chrono::Duration;
 use clap::ArgMatches;
 use clap::ArgMatches;
-use ffsend_api::config::{SEND_DEFAULT_EXPIRE_TIME, SEND_DEFAULT_HOST};
+use ffsend_api::config::SEND_DEFAULT_EXPIRE_TIME;
 use prettytable::{
 use prettytable::{
     cell::Cell,
     cell::Cell,
     format::FormatBuilder,
     format::FormatBuilder,
@@ -9,6 +9,7 @@ use prettytable::{
 };
 };
 
 
 use cmd::matcher::{
 use cmd::matcher::{
+    debug::DebugMatcher,
     main::MainMatcher,
     main::MainMatcher,
     Matcher,
     Matcher,
 };
 };
@@ -33,6 +34,7 @@ impl<'a> Debug<'a> {
     pub fn invoke(&self) -> Result<(), ActionError> {
     pub fn invoke(&self) -> Result<(), ActionError> {
         // Create the command matchers
         // Create the command matchers
         let matcher_main = MainMatcher::with(self.cmd_matches).unwrap();
         let matcher_main = MainMatcher::with(self.cmd_matches).unwrap();
+        let matcher_debug = DebugMatcher::with(self.cmd_matches).unwrap();
 
 
         // Create a table for all debug information
         // Create a table for all debug information
         let mut table = Table::new();
         let mut table = Table::new();
@@ -41,7 +43,7 @@ impl<'a> Debug<'a> {
         // The default host
         // The default host
         table.add_row(Row::new(vec![
         table.add_row(Row::new(vec![
             Cell::new("host:"),
             Cell::new("host:"),
-            Cell::new(SEND_DEFAULT_HOST),
+            Cell::new(matcher_debug.host().as_str()),
         ]));
         ]));
 
 
         // The history file
         // The history file

+ 1 - 0
cli/src/cmd/arg/host.rs

@@ -21,6 +21,7 @@ impl CmdArg for ArgHost {
             .short("h")
             .short("h")
             .value_name("URL")
             .value_name("URL")
             .default_value(SEND_DEFAULT_HOST)
             .default_value(SEND_DEFAULT_HOST)
+            .env("FFSEND_HOST")
             .help("The remote host to upload to")
             .help("The remote host to upload to")
     }
     }
 }
 }

+ 5 - 0
cli/src/cmd/handler.rs

@@ -62,18 +62,21 @@ impl<'a: 'b, 'b> Handler<'a> {
                 .long("force")
                 .long("force")
                 .short("f")
                 .short("f")
                 .global(true)
                 .global(true)
+                .env("FFSEND_FORCE")
                 .help("Force the action, ignore warnings"))
                 .help("Force the action, ignore warnings"))
             .arg(Arg::with_name("no-interact")
             .arg(Arg::with_name("no-interact")
                 .long("no-interact")
                 .long("no-interact")
                 .short("I")
                 .short("I")
                 .alias("no-interactive")
                 .alias("no-interactive")
                 .global(true)
                 .global(true)
+                .env("FFSEND_NO_INTERACT")
                 .help("Not interactive, do not prompt"))
                 .help("Not interactive, do not prompt"))
             .arg(Arg::with_name("yes")
             .arg(Arg::with_name("yes")
                 .long("yes")
                 .long("yes")
                 .short("y")
                 .short("y")
                 .alias("assume-yes")
                 .alias("assume-yes")
                 .global(true)
                 .global(true)
+                .env("FFSEND_YES")
                 .help("Assume yes for prompts"))
                 .help("Assume yes for prompts"))
             .subcommand(CmdDebug::build())
             .subcommand(CmdDebug::build())
             .subcommand(CmdDelete::build())
             .subcommand(CmdDelete::build())
@@ -93,6 +96,7 @@ impl<'a: 'b, 'b> Handler<'a> {
                 .global(true)
                 .global(true)
                 .help("Use the specified history file")
                 .help("Use the specified history file")
                 .default_value(&DEFAULT_HISTORY_FILE)
                 .default_value(&DEFAULT_HISTORY_FILE)
+                .env("FFSEND_HISTORY")
                 .hide_default_value(true))
                 .hide_default_value(true))
             .arg(Arg::with_name("incognito")
             .arg(Arg::with_name("incognito")
                 .long("incognito")
                 .long("incognito")
@@ -101,6 +105,7 @@ impl<'a: 'b, 'b> Handler<'a> {
                 .alias("private")
                 .alias("private")
                 .alias("priv")
                 .alias("priv")
                 .global(true)
                 .global(true)
+                .env("FFSEND_INCOGNITO")
                 .help("Don't update local history for actions"))
                 .help("Don't update local history for actions"))
             .subcommand(CmdHistory::build());
             .subcommand(CmdHistory::build());
 
 

+ 13 - 1
cli/src/cmd/matcher/debug.rs

@@ -1,13 +1,25 @@
 use clap::ArgMatches;
 use clap::ArgMatches;
+use ffsend_api::url::Url;
 
 
+use cmd::arg::{ArgHost, CmdArgOption};
 use super::Matcher;
 use super::Matcher;
 
 
 /// The debug command matcher.
 /// The debug command matcher.
 pub struct DebugMatcher<'a> {
 pub struct DebugMatcher<'a> {
-    #[allow(dead_code)]
     matches: &'a ArgMatches<'a>,
     matches: &'a ArgMatches<'a>,
 }
 }
 
 
+impl<'a: 'b, 'b> DebugMatcher<'a> {
+    /// Get the host to upload to.
+    ///
+    /// This method parses the host into an `Url`.
+    /// If the given host is invalid,
+    /// the program will quit with an error message.
+    pub fn host(&'a self) -> Url {
+        ArgHost::value(self.matches)
+    }
+}
+
 impl<'a> Matcher<'a> for DebugMatcher<'a> {
 impl<'a> Matcher<'a> for DebugMatcher<'a> {
     fn with(matches: &'a ArgMatches) -> Option<Self> {
     fn with(matches: &'a ArgMatches) -> Option<Self> {
         matches.subcommand_matches("debug")
         matches.subcommand_matches("debug")

+ 3 - 0
cli/src/cmd/subcmd/debug.rs

@@ -1,5 +1,7 @@
 use clap::{App, SubCommand};
 use clap::{App, SubCommand};
 
 
+use cmd::arg::{ArgHost, CmdArg};
+
 /// The debug command definition.
 /// The debug command definition.
 pub struct CmdDebug;
 pub struct CmdDebug;
 
 
@@ -8,5 +10,6 @@ impl CmdDebug {
         SubCommand::with_name("debug")
         SubCommand::with_name("debug")
             .about("View debug information")
             .about("View debug information")
             .visible_alias("dbg")
             .visible_alias("dbg")
+            .arg(ArgHost::build().hidden(true))
     }
     }
 }
 }

+ 3 - 0
cli/src/cmd/subcmd/upload.rs

@@ -35,6 +35,7 @@ impl CmdUpload {
             .arg(Arg::with_name("open")
             .arg(Arg::with_name("open")
                 .long("open")
                 .long("open")
                 .short("o")
                 .short("o")
+                .env("FFSEND_OPEN")
                 .help("Open the share link in your browser"));
                 .help("Open the share link in your browser"));
 
 
         // Optional archive support
         // Optional archive support
@@ -43,6 +44,7 @@ impl CmdUpload {
                 .long("archive")
                 .long("archive")
                 .short("a")
                 .short("a")
                 .alias("arch")
                 .alias("arch")
+                .env("FFSEND_ARCHIVE")
                 .help("Package the file as an archive"))
                 .help("Package the file as an archive"))
         }
         }
 
 
@@ -51,6 +53,7 @@ impl CmdUpload {
             cmd = cmd.arg(Arg::with_name("copy")
             cmd = cmd.arg(Arg::with_name("copy")
                 .long("copy")
                 .long("copy")
                 .short("c")
                 .short("c")
+                .env("FFSEND_COPY")
                 .help("Copy the share link to your clipboard"));
                 .help("Copy the share link to your clipboard"));
         } 
         } 
         cmd
         cmd