Add debug flag
This commit is contained in:
parent
a9787d7b5a
commit
088699b2c3
2 changed files with 41 additions and 20 deletions
20
src/cli.rs
20
src/cli.rs
|
@ -38,7 +38,12 @@ It takes a url and downloads the article content from it and saves it to an epub
|
|||
.long("max_conn")
|
||||
.help("The maximum number of concurrent HTTP connections when downloading articles. Default is 8")
|
||||
.long_help("The maximum number of concurrent HTTP connections when downloading articles. Default is 8.\nNOTE: It is advised to use as few connections as needed i.e between 1 and 50. Using more connections can end up overloading your network card with too many concurrent requests.")
|
||||
.takes_value(true));
|
||||
.takes_value(true))
|
||||
.arg(
|
||||
Arg::with_name("debug")
|
||||
.long("debug")
|
||||
.help("Enable logging of events for debugging")
|
||||
.takes_value(false));
|
||||
let arg_matches = app.get_matches();
|
||||
let mut urls: Vec<String> = match arg_matches.value_of("file") {
|
||||
Some(file_name) => {
|
||||
|
@ -84,6 +89,9 @@ It takes a url and downloads the article content from it and saves it to an epub
|
|||
};
|
||||
app_config.set_merged(file_name);
|
||||
}
|
||||
if arg_matches.is_present("debug") {
|
||||
app_config.toggle_debug(true);
|
||||
}
|
||||
app_config
|
||||
}
|
||||
|
||||
|
@ -91,6 +99,7 @@ pub struct AppConfig {
|
|||
urls: Vec<String>,
|
||||
max_conn: usize,
|
||||
merged: Option<String>,
|
||||
is_debug: bool,
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
|
@ -99,9 +108,14 @@ impl AppConfig {
|
|||
urls: vec![],
|
||||
max_conn,
|
||||
merged: None,
|
||||
is_debug: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_debug(&mut self, is_debug: bool) {
|
||||
self.is_debug = is_debug;
|
||||
}
|
||||
|
||||
fn set_urls(&mut self, urls: Vec<String>) {
|
||||
self.urls.extend(urls);
|
||||
}
|
||||
|
@ -120,4 +134,8 @@ impl AppConfig {
|
|||
pub fn merged(&self) -> Option<&String> {
|
||||
self.merged.as_ref()
|
||||
}
|
||||
|
||||
pub fn is_debug(&self) -> bool {
|
||||
self.is_debug
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ fn main() {
|
|||
let app_config = cli::cli_init();
|
||||
|
||||
if !app_config.urls().is_empty() {
|
||||
if app_config.is_debug() {
|
||||
match UserDirs::new() {
|
||||
Some(user_dirs) => {
|
||||
let home_dir = user_dirs.home_dir();
|
||||
|
@ -43,6 +44,7 @@ fn main() {
|
|||
match flexi_logger::Logger::with_str("paperoni=debug")
|
||||
.directory(log_dir)
|
||||
.log_to_file()
|
||||
.print_message()
|
||||
.start()
|
||||
{
|
||||
Ok(_) => (),
|
||||
|
@ -51,6 +53,7 @@ fn main() {
|
|||
}
|
||||
None => eprintln!("Unable to get user directories for logging purposes"),
|
||||
};
|
||||
}
|
||||
download(app_config);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue