I’ve encountered an error: ‘a value is required for –subdomains <Subdomains> but none was supplied’. This error occurs when I run the command cargo run – -d xyz.com -s. I want -s to act just as a flag, but it’s causing an error. Here’s the code I’m working with:
use clap::{command, Arg};
use reqwest::{Client};
#[tokio::main]
async fn main() {
println!("Waybackurls");
let arguments = command!()
.about("Retrieves encoded emails from the application and subsequently decodes them")
.author("Anonymous")
.version("1.0.0")
.arg(
Arg::new("Domain")
.short('d')
.long("domain")
.required(true)
.help("Domain here")
)
.arg(
Arg::new("Subdomains")
.short('s')
.long("subdomains")
.required(false)
.help("To fetch subdomains from the urls")
)
.get_matches();
let domain = arguments.get_one::<String>("Domain");
// variable
let subdomains = if arguments.contains_id("Subdomains") {
"*.".to_string()
} else {
"".to_string()
};
let http_get = Client::new();
// let mut urls: Vec<String> = Vec::new();
let waybakck_url = match domain {
Some(domain) => {
format!("http://web.archive.org/cdx/search/cdx?url={}{}/*&output=json&fl=original&collapse=urlkey",subdomains,domain)
},
None => String::from("Provide valid domain")
};
let response = http_get.get(waybakck_url)
.send()
.await
.expect("Error fetching wayback machine urls");
if response.status().is_success() {
let wburls = response.text().await.expect("Error");
print!("{}",wburls.replace("[", "").replace("]", "").replace("\"", "").replace(",", ""));
}
}
I attempted to use the default_value() function, but I’m still encountering the same error.