2019-10-10 05:28:12 +00:00
|
|
|
use clap::{App, Arg};
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct AppArgs {
|
2020-04-02 07:04:21 +00:00
|
|
|
pub target: String,
|
2019-10-10 05:28:12 +00:00
|
|
|
pub no_css: bool,
|
|
|
|
pub no_frames: bool,
|
|
|
|
pub no_images: bool,
|
|
|
|
pub no_js: bool,
|
|
|
|
pub insecure: bool,
|
|
|
|
pub isolate: bool,
|
2019-12-26 05:41:03 +00:00
|
|
|
pub output: String,
|
2019-10-10 05:28:12 +00:00
|
|
|
pub silent: bool,
|
2020-02-03 05:38:21 +00:00
|
|
|
pub timeout: u64,
|
2019-10-10 05:28:12 +00:00
|
|
|
pub user_agent: String,
|
|
|
|
}
|
|
|
|
|
2020-02-03 05:38:21 +00:00
|
|
|
const DEFAULT_NETWORK_TIMEOUT: u64 = 120;
|
2019-10-10 05:28:12 +00:00
|
|
|
const DEFAULT_USER_AGENT: &str =
|
2020-02-15 06:33:20 +00:00
|
|
|
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0";
|
2019-10-10 05:28:12 +00:00
|
|
|
|
|
|
|
impl AppArgs {
|
|
|
|
pub fn get() -> AppArgs {
|
2020-02-14 04:46:08 +00:00
|
|
|
let app = App::new(env!("CARGO_PKG_NAME"))
|
2019-10-10 05:28:12 +00:00
|
|
|
.version(crate_version!())
|
|
|
|
.author(crate_authors!("\n"))
|
|
|
|
.about(crate_description!())
|
|
|
|
.arg(
|
2020-04-02 07:04:21 +00:00
|
|
|
Arg::with_name("target")
|
2019-10-10 05:28:12 +00:00
|
|
|
.required(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.index(1)
|
2020-04-02 07:04:21 +00:00
|
|
|
.help("URL or file path"),
|
2019-10-10 05:28:12 +00:00
|
|
|
)
|
2020-02-15 06:33:20 +00:00
|
|
|
// .args_from_usage("-a, --include-audio 'Removes audio sources'")
|
|
|
|
.args_from_usage("-c, --no-css 'Removes CSS'")
|
2020-02-24 05:06:31 +00:00
|
|
|
.args_from_usage("-f, --no-frames 'Removes frames and iframes'")
|
2020-02-15 06:33:20 +00:00
|
|
|
.args_from_usage("-i, --no-images 'Removes images'")
|
|
|
|
.args_from_usage("-I, --isolate 'Cuts off document from the Internet'")
|
|
|
|
.args_from_usage("-j, --no-js 'Removes JavaScript'")
|
|
|
|
.args_from_usage("-k, --insecure 'Allows invalid X.509 (TLS) certificates'")
|
|
|
|
.args_from_usage("-o, --output=[document.html] 'Writes output to <file>'")
|
|
|
|
.args_from_usage("-s, --silent 'Suppresses verbosity'")
|
|
|
|
.args_from_usage("-t, --timeout=[60] 'Adjusts network request timeout'")
|
|
|
|
.args_from_usage("-u, --user-agent=[Firefox] 'Sets custom User-Agent string'")
|
|
|
|
// .args_from_usage("-v, --include-video 'Removes video sources'")
|
2019-10-10 05:28:12 +00:00
|
|
|
.get_matches();
|
|
|
|
let mut app_args = AppArgs::default();
|
|
|
|
// Process the command
|
2020-04-02 07:04:21 +00:00
|
|
|
app_args.target = app
|
|
|
|
.value_of("target")
|
|
|
|
.expect("please set target")
|
2019-10-10 05:28:12 +00:00
|
|
|
.to_string();
|
|
|
|
app_args.no_css = app.is_present("no-css");
|
|
|
|
app_args.no_frames = app.is_present("no-frames");
|
|
|
|
app_args.no_images = app.is_present("no-images");
|
|
|
|
app_args.no_js = app.is_present("no-js");
|
|
|
|
app_args.insecure = app.is_present("insecure");
|
|
|
|
app_args.isolate = app.is_present("isolate");
|
|
|
|
app_args.silent = app.is_present("silent");
|
2020-02-03 05:38:21 +00:00
|
|
|
app_args.timeout = app
|
|
|
|
.value_of("timeout")
|
|
|
|
.unwrap_or(&DEFAULT_NETWORK_TIMEOUT.to_string())
|
|
|
|
.parse::<u64>()
|
|
|
|
.unwrap();
|
2019-12-26 05:41:03 +00:00
|
|
|
app_args.output = app.value_of("output").unwrap_or("").to_string();
|
2019-10-10 05:28:12 +00:00
|
|
|
app_args.user_agent = app
|
|
|
|
.value_of("user-agent")
|
2020-01-03 22:58:29 +00:00
|
|
|
.unwrap_or(DEFAULT_USER_AGENT)
|
2019-10-10 05:28:12 +00:00
|
|
|
.to_string();
|
|
|
|
app_args
|
|
|
|
}
|
|
|
|
}
|