mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-05 02:09:27 +02:00
Implement quiet CLI flag, only report URLs for history with quiet
This commit is contained in:
parent
3ea774e227
commit
5ac3cd4b15
4 changed files with 64 additions and 41 deletions
|
@ -275,6 +275,7 @@ empty.
|
|||
| `FFSEND_ARCHIVE` | `--archive` | Archive files uploaded |
|
||||
| `FFSEND_EXTRACT` | `--extract` | Extract files downloaded |
|
||||
| `FFSEND_COPY` | `--copy` | Copy share link to clipboard |
|
||||
| `FFSEND_QUIET` | `--quiet` | Log quiet information |
|
||||
| `FFSEND_VERBOSE` | `--verbose` | Log verbose information |
|
||||
|
||||
At this time, no configuration or _dotfile_ file support is available.
|
||||
|
|
|
@ -26,7 +26,9 @@ impl<'a> History<'a> {
|
|||
// Get the history path, make sure it exists
|
||||
let history_path = matcher_main.history();
|
||||
if !history_path.is_file() {
|
||||
if !matcher_main.quiet() {
|
||||
eprintln!("No files in history");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -35,10 +37,18 @@ impl<'a> History<'a> {
|
|||
|
||||
// Do not report any files if there aren't any
|
||||
if history.files().is_empty() {
|
||||
if !matcher_main.quiet() {
|
||||
eprintln!("No files in history");
|
||||
}
|
||||
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
|
||||
let mut columns = vec!["#", "LINK", "EXPIRY"];
|
||||
if matcher_main.verbose() {
|
||||
|
@ -52,10 +62,6 @@ impl<'a> History<'a> {
|
|||
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
|
||||
for (i, file) in files.iter().enumerate() {
|
||||
// Build the expiry time string
|
||||
|
@ -89,6 +95,10 @@ impl<'a> History<'a> {
|
|||
// Print the table
|
||||
table.printstd();
|
||||
|
||||
} else {
|
||||
files.iter().for_each(|f| println!("{}", f.download_url(true)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::with_name("verbose")
|
||||
.long("verbose")
|
||||
|
|
|
@ -71,6 +71,11 @@ impl<'a: 'b, 'b> MainMatcher<'a> {
|
|||
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.
|
||||
pub fn verbose(&self) -> bool {
|
||||
self.matches.is_present("verbose") || env_var_present("FFSEND_VERBOSE")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue