Implement quiet CLI flag, only report URLs for history with quiet

This commit is contained in:
timvisee 2018-11-21 21:55:19 +01:00
parent 3ea774e227
commit 5ac3cd4b15
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
4 changed files with 64 additions and 41 deletions

View file

@ -275,6 +275,7 @@ empty.
| `FFSEND_ARCHIVE` | `--archive` | Archive files uploaded | | `FFSEND_ARCHIVE` | `--archive` | Archive files uploaded |
| `FFSEND_EXTRACT` | `--extract` | Extract files downloaded | | `FFSEND_EXTRACT` | `--extract` | Extract files downloaded |
| `FFSEND_COPY` | `--copy` | Copy share link to clipboard | | `FFSEND_COPY` | `--copy` | Copy share link to clipboard |
| `FFSEND_QUIET` | `--quiet` | Log quiet information |
| `FFSEND_VERBOSE` | `--verbose` | Log verbose information | | `FFSEND_VERBOSE` | `--verbose` | Log verbose information |
At this time, no configuration or _dotfile_ file support is available. At this time, no configuration or _dotfile_ file support is available.

View file

@ -26,7 +26,9 @@ impl<'a> History<'a> {
// Get the history path, make sure it exists // Get the history path, make sure it exists
let history_path = matcher_main.history(); let history_path = matcher_main.history();
if !history_path.is_file() { if !history_path.is_file() {
if !matcher_main.quiet() {
eprintln!("No files in history"); eprintln!("No files in history");
}
return Ok(()); return Ok(());
} }
@ -35,10 +37,18 @@ impl<'a> History<'a> {
// Do not report any files if there aren't any // Do not report any files if there aren't any
if history.files().is_empty() { if history.files().is_empty() {
if !matcher_main.quiet() {
eprintln!("No files in history"); eprintln!("No files in history");
}
return Ok(()); return Ok(());
} }
// Get the list of files, and sort the first expiring files to be last
let mut files = history.files().clone();
files.sort_by(|a, b| b.expire_at().cmp(&a.expire_at()));
// Log a history table, or just the URLs in quiet mode
if !matcher_main.quiet() {
// Build the list of column names // Build the list of column names
let mut columns = vec!["#", "LINK", "EXPIRY"]; let mut columns = vec!["#", "LINK", "EXPIRY"];
if matcher_main.verbose() { if matcher_main.verbose() {
@ -52,10 +62,6 @@ impl<'a> History<'a> {
columns.into_iter().map(Cell::new).collect(), columns.into_iter().map(Cell::new).collect(),
)); ));
// Get the list of files, and sort the first expiring files to be last
let mut files = history.files().clone();
files.sort_by(|a, b| b.expire_at().cmp(&a.expire_at()));
// Add an entry for each file // Add an entry for each file
for (i, file) in files.iter().enumerate() { for (i, file) in files.iter().enumerate() {
// Build the expiry time string // Build the expiry time string
@ -89,6 +95,10 @@ impl<'a> History<'a> {
// Print the table // Print the table
table.printstd(); table.printstd();
} else {
files.iter().for_each(|f| println!("{}", f.download_url(true)));
}
Ok(()) Ok(())
} }
} }

View file

@ -123,6 +123,13 @@ impl<'a: 'b, 'b> Handler<'a> {
)) ))
), ),
) )
.arg(
Arg::with_name("quiet")
.long("quiet")
.short("q")
.global(true)
.help("Produce output suitable for logging and automation"),
)
.arg( .arg(
Arg::with_name("verbose") Arg::with_name("verbose")
.long("verbose") .long("verbose")

View file

@ -71,6 +71,11 @@ impl<'a: 'b, 'b> MainMatcher<'a> {
self.matches.is_present("incognito") || env_var_present("FFSEND_INCOGNITO") self.matches.is_present("incognito") || env_var_present("FFSEND_INCOGNITO")
} }
/// Check whether quiet mode is used.
pub fn quiet(&self) -> bool {
!self.verbose() && (self.matches.is_present("quiet") || env_var_present("FFSEND_QUIET"))
}
/// Check whether verbose mode is used. /// Check whether verbose mode is used.
pub fn verbose(&self) -> bool { pub fn verbose(&self) -> bool {
self.matches.is_present("verbose") || env_var_present("FFSEND_VERBOSE") self.matches.is_present("verbose") || env_var_present("FFSEND_VERBOSE")