"verbose" CLI param
This commit is contained in:
parent
4eb0627a5f
commit
79bc8e67a7
3 changed files with 22 additions and 3 deletions
1
notes.md
1
notes.md
|
|
@ -48,7 +48,6 @@
|
||||||
- cli functions
|
- cli functions
|
||||||
- "continue" and "new" flags to avoid user interaction
|
- "continue" and "new" flags to avoid user interaction
|
||||||
- "quiet" flag to disable output entirely
|
- "quiet" flag to disable output entirely
|
||||||
- "verbose" flag to adjust RUST_LOG for `shrupl` crate
|
|
||||||
- some switch to change log to "pretty-print"
|
- some switch to change log to "pretty-print"
|
||||||
|
|
||||||
- client error rework
|
- client error rework
|
||||||
|
|
|
||||||
16
src/cli.rs
16
src/cli.rs
|
|
@ -11,6 +11,7 @@ use clap::{
|
||||||
builder::{PossibleValuesParser, TypedValueParser},
|
builder::{PossibleValuesParser, TypedValueParser},
|
||||||
value_parser,
|
value_parser,
|
||||||
};
|
};
|
||||||
|
use log::LevelFilter;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
file::Checked,
|
file::Checked,
|
||||||
|
|
@ -60,6 +61,10 @@ pub struct Cli {
|
||||||
)]
|
)]
|
||||||
pub chunk_size: usize,
|
pub chunk_size: usize,
|
||||||
|
|
||||||
|
/// Increase output verbosity
|
||||||
|
#[arg(short, long, action = clap::ArgAction::Count)]
|
||||||
|
verbose: u8,
|
||||||
|
|
||||||
/// Base URL for Sharry Instance
|
/// Base URL for Sharry Instance
|
||||||
url: String,
|
url: String,
|
||||||
|
|
||||||
|
|
@ -81,6 +86,7 @@ impl fmt::Debug for Cli {
|
||||||
.field("chunk_size", &self.chunk_size)
|
.field("chunk_size", &self.chunk_size)
|
||||||
.field("share_request", &self.get_share_request())
|
.field("share_request", &self.get_share_request())
|
||||||
.field("files", &self.files)
|
.field("files", &self.files)
|
||||||
|
.field("level_filter", &self.get_level_filter())
|
||||||
.field("hash", &self.get_hash())
|
.field("hash", &self.get_hash())
|
||||||
.finish_non_exhaustive()
|
.finish_non_exhaustive()
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +120,16 @@ impl Cli {
|
||||||
NewShareRequest::new(&self.name, self.description.as_ref(), self.max_views)
|
NewShareRequest::new(&self.name, self.description.as_ref(), self.max_views)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_level_filter(&self) -> LevelFilter {
|
||||||
|
match self.verbose {
|
||||||
|
0 => LevelFilter::Error,
|
||||||
|
1 => LevelFilter::Warn,
|
||||||
|
2 => LevelFilter::Info,
|
||||||
|
3 => LevelFilter::Debug,
|
||||||
|
_ => LevelFilter::Trace,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_hash(&self) -> String {
|
pub fn get_hash(&self) -> String {
|
||||||
let file_refs = {
|
let file_refs = {
|
||||||
let mut refs: Vec<_> = self.files.iter().collect();
|
let mut refs: Vec<_> = self.files.iter().collect();
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ use cli::Cli;
|
||||||
use output::{Log, SHRUPL, prompt_continue};
|
use output::{Log, SHRUPL, prompt_continue};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
|
||||||
|
|
||||||
let check_ctrlc = {
|
let check_ctrlc = {
|
||||||
let stop = Arc::new(AtomicBool::new(false));
|
let stop = Arc::new(AtomicBool::new(false));
|
||||||
let stop_ctrlc = stop.clone();
|
let stop_ctrlc = stop.clone();
|
||||||
|
|
@ -43,6 +41,12 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
|
|
||||||
|
env_logger::Builder::new()
|
||||||
|
.filter_module("shrupl", args.get_level_filter())
|
||||||
|
.parse_default_env()
|
||||||
|
.init();
|
||||||
|
|
||||||
info!("args: {args:#?}");
|
info!("args: {args:#?}");
|
||||||
|
|
||||||
println!("{} to {}!", style("Welcome").magenta().bold(), *SHRUPL);
|
println!("{} to {}!", style("Welcome").magenta().bold(), *SHRUPL);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue