From 2b96f9a32afd2142f97240531753ca08adca8a51 Mon Sep 17 00:00:00 2001 From: Vincent Flyson Date: Sun, 25 Aug 2019 11:41:30 -0400 Subject: [PATCH] Add flag for silent mode --- Cargo.toml | 2 +- README.md | 1 + src/html.rs | 10 ++++++++++ src/http.rs | 11 +++++++---- src/main.rs | 9 ++++++--- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55f8b4e..3490512 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "monolith" -version = "2.0.13" +version = "2.0.14" authors = [ "Sunshine ", "Mahdi Robatipoor ", diff --git a/README.md b/README.md index 4e494c6..362a9b8 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ If compared to saving websites with `wget -mpk`, `monolith` embeds all assets as ### Options - `-i`: Remove images - `-j`: Exclude JavaScript + - `-s`: Silent mode - `-u`: Specify custom User-Agent ### License diff --git a/src/html.rs b/src/html.rs index e51d58a..8aadb1a 100644 --- a/src/html.rs +++ b/src/html.rs @@ -69,6 +69,7 @@ pub fn walk_and_embed_assets( opt_no_js: bool, opt_no_images: bool, opt_user_agent: &str, + opt_silent: bool, ) { match node.data { NodeData::Document => { @@ -79,6 +80,7 @@ pub fn walk_and_embed_assets( opt_no_js, opt_no_images, opt_user_agent, + opt_silent, ); } } @@ -130,6 +132,7 @@ pub fn walk_and_embed_assets( true, "", opt_user_agent, + opt_silent, ).unwrap_or(EMPTY_STRING.clone()); attr.value.clear(); attr.value.push_slice(favicon_datauri.as_str()); @@ -149,6 +152,7 @@ pub fn walk_and_embed_assets( true, "text/css", opt_user_agent, + opt_silent, ).unwrap_or(EMPTY_STRING.clone()); attr.value.clear(); attr.value.push_slice(css_datauri.as_str()); @@ -185,6 +189,7 @@ pub fn walk_and_embed_assets( true, "", opt_user_agent, + opt_silent, ).unwrap_or(EMPTY_STRING.clone()); attr.value.clear(); attr.value.push_slice(img_datauri.as_str()); @@ -210,6 +215,7 @@ pub fn walk_and_embed_assets( true, "", opt_user_agent, + opt_silent, ).unwrap_or(EMPTY_STRING.clone()); attr.value.clear(); attr.value.push_slice(source_datauri.as_str()); @@ -255,6 +261,7 @@ pub fn walk_and_embed_assets( true, "application/javascript", opt_user_agent, + opt_silent, ).unwrap_or(EMPTY_STRING.clone()); attr.value.clear(); attr.value.push_slice(js_datauri.as_str()); @@ -287,6 +294,7 @@ pub fn walk_and_embed_assets( false, "text/html", opt_user_agent, + opt_silent, ).unwrap_or(EMPTY_STRING.clone()); let dom = html_to_dom(&iframe_data); walk_and_embed_assets( @@ -295,6 +303,7 @@ pub fn walk_and_embed_assets( opt_no_js, opt_no_images, opt_user_agent, + opt_silent, ); let mut buf: Vec = Vec::new(); serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); @@ -324,6 +333,7 @@ pub fn walk_and_embed_assets( opt_no_js, opt_no_images, opt_user_agent, + opt_silent, ); } } diff --git a/src/http.rs b/src/http.rs index 5708076..af39b90 100644 --- a/src/http.rs +++ b/src/http.rs @@ -36,6 +36,7 @@ pub fn retrieve_asset( as_dataurl: bool, as_mime: &str, opt_user_agent: &str, + opt_silent: bool ) -> Result { if is_data_url(&url).unwrap() { Ok(url.to_string()) @@ -49,10 +50,12 @@ pub fn retrieve_asset( .send()?; let final_url = response.url().as_str(); - if url == final_url { - eprintln!("[ {} ]", &url); - } else { - eprintln!("[ {} -> {} ]", &url, &final_url); + if !opt_silent { + if url == final_url { + eprintln!("[ {} ]", &url); + } else { + eprintln!("[ {} -> {} ]", &url, &final_url); + } } if as_dataurl { diff --git a/src/main.rs b/src/main.rs index a8a768e..af229b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,19 +21,21 @@ fn main() { .index(1) .help("URL to download"), ) - .args_from_usage("-j, --no-js 'Excludes JavaScript'") .args_from_usage("-i, --no-images 'Removes images'") + .args_from_usage("-j, --no-js 'Excludes JavaScript'") + .args_from_usage("-s, --silent 'Suppress verbosity'") .args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'") .get_matches(); // Process the command let arg_target = command.value_of("url").unwrap(); - let opt_no_js = command.is_present("no-js"); let opt_no_images = command.is_present("no-images"); + let opt_no_js = command.is_present("no-js"); + let opt_silent = command.is_present("silent"); let opt_user_agent = command.value_of("user-agent").unwrap_or(DEFAULT_USER_AGENT); if is_valid_url(arg_target) { - let data = retrieve_asset(&arg_target, false, "", opt_user_agent).unwrap(); + let data = retrieve_asset(&arg_target, false, "", opt_user_agent, opt_silent).unwrap(); let dom = html_to_dom(&data); walk_and_embed_assets( @@ -42,6 +44,7 @@ fn main() { opt_no_js, opt_no_images, opt_user_agent, + opt_silent, ); print_dom(&dom.document);