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_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.
|
||||||
|
|
|
@ -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() {
|
||||||
eprintln!("No files in history");
|
if !matcher_main.quiet() {
|
||||||
|
eprintln!("No files in history");
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,59 +37,67 @@ 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() {
|
||||||
eprintln!("No files in history");
|
if !matcher_main.quiet() {
|
||||||
|
eprintln!("No files in history");
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the list of column names
|
|
||||||
let mut columns = vec!["#", "LINK", "EXPIRY"];
|
|
||||||
if matcher_main.verbose() {
|
|
||||||
columns.push("OWNER TOKEN");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new table
|
|
||||||
let mut table = Table::new();
|
|
||||||
table.set_format(FormatBuilder::new().padding(0, 2).build());
|
|
||||||
table.add_row(Row::new(
|
|
||||||
columns.into_iter().map(Cell::new).collect(),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Get the list of files, and sort the first expiring files to be last
|
// Get the list of files, and sort the first expiring files to be last
|
||||||
let mut files = history.files().clone();
|
let mut files = history.files().clone();
|
||||||
files.sort_by(|a, b| b.expire_at().cmp(&a.expire_at()));
|
files.sort_by(|a, b| b.expire_at().cmp(&a.expire_at()));
|
||||||
|
|
||||||
// Add an entry for each file
|
// Log a history table, or just the URLs in quiet mode
|
||||||
for (i, file) in files.iter().enumerate() {
|
if !matcher_main.quiet() {
|
||||||
// Build the expiry time string
|
// Build the list of column names
|
||||||
let mut expiry = format_duration(&file.expire_duration());
|
let mut columns = vec!["#", "LINK", "EXPIRY"];
|
||||||
if file.expire_uncertain() {
|
|
||||||
expiry.insert(0, '~');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the owner token
|
|
||||||
let owner_token: String = match file.owner_token() {
|
|
||||||
Some(token) => token.clone(),
|
|
||||||
None => "?".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Define the cell values
|
|
||||||
let mut cells: Vec<String>= vec![
|
|
||||||
format!("{}", i + 1),
|
|
||||||
file.download_url(true).into_string(),
|
|
||||||
expiry,
|
|
||||||
];
|
|
||||||
if matcher_main.verbose() {
|
if matcher_main.verbose() {
|
||||||
cells.push(owner_token);
|
columns.push("OWNER TOKEN");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the row
|
// Create a new table
|
||||||
|
let mut table = Table::new();
|
||||||
|
table.set_format(FormatBuilder::new().padding(0, 2).build());
|
||||||
table.add_row(Row::new(
|
table.add_row(Row::new(
|
||||||
cells.into_iter().map(|c| Cell::new(&c)).collect(),
|
columns.into_iter().map(Cell::new).collect(),
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
// Print the table
|
// Add an entry for each file
|
||||||
table.printstd();
|
for (i, file) in files.iter().enumerate() {
|
||||||
|
// Build the expiry time string
|
||||||
|
let mut expiry = format_duration(&file.expire_duration());
|
||||||
|
if file.expire_uncertain() {
|
||||||
|
expiry.insert(0, '~');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the owner token
|
||||||
|
let owner_token: String = match file.owner_token() {
|
||||||
|
Some(token) => token.clone(),
|
||||||
|
None => "?".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define the cell values
|
||||||
|
let mut cells: Vec<String>= vec![
|
||||||
|
format!("{}", i + 1),
|
||||||
|
file.download_url(true).into_string(),
|
||||||
|
expiry,
|
||||||
|
];
|
||||||
|
if matcher_main.verbose() {
|
||||||
|
cells.push(owner_token);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the row
|
||||||
|
table.add_row(Row::new(
|
||||||
|
cells.into_iter().map(|c| Cell::new(&c)).collect(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the table
|
||||||
|
table.printstd();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
files.iter().for_each(|f| println!("{}", f.download_url(true)));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
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(
|
||||||
Arg::with_name("verbose")
|
Arg::with_name("verbose")
|
||||||
.long("verbose")
|
.long("verbose")
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue