Define environment variables for CLI arguments

This commit is contained in:
timvisee 2018-05-17 17:04:16 +02:00
parent dd65b51cb5
commit 36c8c355d2
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
8 changed files with 41 additions and 4 deletions

View file

@ -9,3 +9,15 @@ toolchain.
- Ubuntu package: `libssl-dev`
- On Linux, `xorg` development packages (for `clipboard` feature)
- 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)

View file

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

View file

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

View file

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

View file

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

View file

@ -1,13 +1,25 @@
use clap::ArgMatches;
use ffsend_api::url::Url;
use cmd::arg::{ArgHost, CmdArgOption};
use super::Matcher;
/// The debug command matcher.
pub struct DebugMatcher<'a> {
#[allow(dead_code)]
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> {
fn with(matches: &'a ArgMatches) -> Option<Self> {
matches.subcommand_matches("debug")

View file

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

View file

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