rename -D to -d, allow multiple occurrences
This commit is contained in:
parent
3fa3a0222a
commit
145550e637
3 changed files with 30 additions and 23 deletions
|
@ -113,7 +113,7 @@ cat index.html | monolith -aIiFfcMv -b https://original.site/ - > result.html
|
||||||
- `-b`: Use custom `base URL`
|
- `-b`: Use custom `base URL`
|
||||||
- `-c`: Exclude CSS
|
- `-c`: Exclude CSS
|
||||||
- `-C`: Save document using custom `charset`
|
- `-C`: Save document using custom `charset`
|
||||||
- `-D`: Allow retrieving assets only from specified `domain(s)`
|
- `-d`: Allow retrieving assets only from specified `domain(s)`
|
||||||
- `-e`: Ignore network errors
|
- `-e`: Ignore network errors
|
||||||
- `-E`: Exclude all assets located within domains specified in whitelist
|
- `-E`: Exclude all assets located within domains specified in whitelist
|
||||||
- `-f`: Omit frames
|
- `-f`: Omit frames
|
||||||
|
|
26
src/opts.rs
26
src/opts.rs
|
@ -1,4 +1,4 @@
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg, ArgAction};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -52,9 +52,17 @@ impl Options {
|
||||||
.args_from_usage("-b, --base-url=[http://localhost/] 'Sets custom base URL'")
|
.args_from_usage("-b, --base-url=[http://localhost/] 'Sets custom base URL'")
|
||||||
.args_from_usage("-c, --no-css 'Removes CSS'")
|
.args_from_usage("-c, --no-css 'Removes CSS'")
|
||||||
.args_from_usage("-C, --charset=[UTF-8] 'Enforces custom encoding'")
|
.args_from_usage("-C, --charset=[UTF-8] 'Enforces custom encoding'")
|
||||||
.args_from_usage("-D, --domains=[bad.org,ads.site] 'Whitelist of domains'")
|
.arg(
|
||||||
|
Arg::with_name("domains")
|
||||||
|
.short('d')
|
||||||
|
.long("domains")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("DOMAINS")
|
||||||
|
.action(ArgAction::Append)
|
||||||
|
.help("Whitelist of domains"),
|
||||||
|
)
|
||||||
.args_from_usage("-e, --ignore-errors 'Ignore network errors'")
|
.args_from_usage("-e, --ignore-errors 'Ignore network errors'")
|
||||||
.args_from_usage("-E, --exclude-domains 'Treat list of specified domains as blacklist'")
|
.args_from_usage("-E, --exclude-domains 'Treat specified domains as blacklist'")
|
||||||
.args_from_usage("-f, --no-frames 'Removes frames and iframes'")
|
.args_from_usage("-f, --no-frames 'Removes frames and iframes'")
|
||||||
.args_from_usage("-F, --no-fonts 'Removes fonts'")
|
.args_from_usage("-F, --no-fonts 'Removes fonts'")
|
||||||
.args_from_usage("-i, --no-images 'Removes images'")
|
.args_from_usage("-i, --no-images 'Removes images'")
|
||||||
|
@ -95,8 +103,16 @@ impl Options {
|
||||||
if let Some(charset) = app.value_of("charset") {
|
if let Some(charset) = app.value_of("charset") {
|
||||||
options.charset = Some(charset.to_string());
|
options.charset = Some(charset.to_string());
|
||||||
}
|
}
|
||||||
if let Some(domains) = app.value_of("domains") {
|
if let Some(domains) = app.get_many::<String>("domains") {
|
||||||
options.domains = Some(domains.split(",").map(|s| s.to_string()).collect());
|
let mut final_list_of_domains: Vec<String> = Vec::new();
|
||||||
|
let provided_arguments: Vec<&str> = domains.map(|v| v.as_str()).collect::<Vec<_>>();
|
||||||
|
for provided_argument in provided_arguments {
|
||||||
|
let comma_separated_domains: Vec<&str> = provided_argument.split(",").collect();
|
||||||
|
for comma_separated_domain in comma_separated_domains {
|
||||||
|
final_list_of_domains.push(comma_separated_domain.trim().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options.domains = Some(final_list_of_domains);
|
||||||
}
|
}
|
||||||
options.ignore_errors = app.is_present("ignore-errors");
|
options.ignore_errors = app.is_present("ignore-errors");
|
||||||
options.exclude_domains = app.is_present("exclude-domains");
|
options.exclude_domains = app.is_present("exclude-domains");
|
||||||
|
|
25
src/utils.rs
25
src/utils.rs
|
@ -266,23 +266,14 @@ pub fn retrieve_asset(
|
||||||
"".to_string(),
|
"".to_string(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
if options.exclude_domains {
|
if let Some(domains) = &options.domains {
|
||||||
if let Some(domains) = &options.domains {
|
let domain_matches = domains
|
||||||
if domains
|
.iter()
|
||||||
.iter()
|
.any(|d| domain_is_within_domain(url.host_str().unwrap(), &d.trim()));
|
||||||
.any(|d| domain_is_within_domain(url.host_str().unwrap(), &d.trim()))
|
if (options.exclude_domains && domain_matches)
|
||||||
{
|
|| (!options.exclude_domains && !domain_matches)
|
||||||
return Err(client.get("").send().unwrap_err());
|
{
|
||||||
}
|
return Err(client.get("").send().unwrap_err());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(domains) = &options.domains {
|
|
||||||
if domains
|
|
||||||
.iter()
|
|
||||||
.any(|d| !domain_is_within_domain(url.host_str().unwrap(), &d.trim()))
|
|
||||||
{
|
|
||||||
return Err(client.get("").send().unwrap_err());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue