//! Command-line interface (clap). use std::path::PathBuf; use clap::{Args, Parser, Subcommand, ValueEnum}; use clap_complete::Shell; const LONG_ABOUT: &str = "Percival checks a username (or email) against thousands of sites drawn from the \ WhatsMyName, Sherlock and Maigret databases, verifies every hit against a canary account so broken \ detectors don't pollute results, extracts profile metadata, pivots on handles it discovers, checks the \ Wayback Machine for deleted accounts, and writes HTML / JSON / CSV / Markdown / DOT reports.\n\n\ Examples:\n percival johndoe\n percival johndoe -c social,coding --only-found -o\n percival johndoe --recursive --archive --formats all -o reports/\n percival john.doe --permute --top 300\n percival email john.doe@example.com\n percival sites --filter 'cat=coding and rank<=500'\n percival selfcheck --site github --write"; #[derive(Parser, Debug)] #[command(name = crate::NAME, version, about = crate::TAGLINE, long_about = LONG_ABOUT, propagate_version = true)] pub struct Cli { #[command(subcommand)] pub command: Option, /// Usernames to search (default command). #[arg(value_name = "USERNAME")] pub targets: Vec, #[command(flatten)] pub scan: ScanArgs, #[command(flatten)] pub global: GlobalArgs, } #[derive(Args, Debug, Clone, Default)] pub struct GlobalArgs { /// Increase log verbosity (-v info, -vv debug, -vvv trace). #[arg(short = 'v', long, action = clap::ArgAction::Count, global = true)] pub verbose: u8, /// Suppress banner, progress and non-result output. #[arg(short = 'q', long, global = true)] pub quiet: bool, /// Disable colours. #[arg(long, global = true)] pub no_color: bool, /// Disable the animated startup banner. #[arg(long, global = true)] pub no_anim: bool, /// Theme: rose-pine, rose-pine-moon, rose-pine-dawn or none. #[arg(long, global = true, value_name = "NAME")] pub theme: Option, /// Config file (default: ~/.config/percival/config.toml). #[arg(long, global = true, value_name = "FILE")] pub config: Option, /// Data directory for updated databases and self-check overlay. #[arg(long, global = true, value_name = "DIR")] pub data_dir: Option, } #[derive(Subcommand, Debug)] pub enum Command { /// Search usernames across every site (the default when no subcommand is given). Search(SearchArgs), /// Search an email address: Gravatar, GitHub, breach data and derived handles. Email(EmailArgs), /// List, inspect and count the sites in the database. Sites(SitesArgs), /// Test every detector against known accounts and a canary; optionally disable broken sites. Selfcheck(SelfcheckArgs), /// Download the latest WhatsMyName, Sherlock and Maigret databases. Update(UpdateArgs), /// Print username permutations without searching. Permute(PermuteArgs), /// Extract handles from profile URLs (or from the pages behind them). Parse(ParseArgs), /// Generate shell completions. Completions { #[arg(value_enum)] shell: Shell, }, /// Show or create the config file. Config(ConfigArgs), } #[derive(Args, Debug, Clone, Default)] pub struct SearchArgs { /// Usernames to search. #[arg(value_name = "USERNAME")] pub targets: Vec, #[command(flatten)] pub scan: ScanArgs, } #[derive(Args, Debug, Clone, Default)] pub struct EmailArgs { /// Email addresses to search. #[arg(value_name = "EMAIL", required = true)] pub emails: Vec, /// Don't derive and search usernames from the local part. #[arg(long)] pub no_derive: bool, /// Have I Been Pwned API key (or set hibp_api_key in the config). #[arg(long, value_name = "KEY", env = "HIBP_API_KEY")] pub hibp_key: Option, #[command(flatten)] pub scan: ScanArgs, } /// Which sites take part. #[derive(Args, Debug, Clone, Default)] #[command(next_help_heading = "Site selection")] pub struct SelectArgs { /// Only these categories (comma separated): social, coding, gaming, forum, … #[arg(short = 'c', long, value_delimiter = ',', value_name = "CAT")] pub category: Vec, /// Only sites carrying a tag (Maigret tags, country codes like "ru", "engine:discourse"). #[arg(long, value_delimiter = ',', value_name = "TAG")] pub tag: Vec, /// Only sites whose name or host contains this text (comma separated). #[arg(short = 's', long = "site", value_delimiter = ',', value_name = "NAME")] pub sites: Vec, /// Skip sites whose name or host contains this text. #[arg( short = 'x', long = "exclude", value_delimiter = ',', value_name = "NAME" )] pub exclude: Vec, /// Only these databases: wmn, sherlock, maigret, percival, custom. #[arg(long, value_delimiter = ',', value_name = "SRC")] pub source: Vec, /// Filter expression, e.g. "cat=social and not protection~cloudflare". #[arg(short = 'F', long, value_name = "EXPR")] pub filter: Option, /// Include the long tail of unranked Maigret sites (thousands of small forums). #[arg(long)] pub all_sites: bool, /// Only the N most popular sites. #[arg(long, value_name = "N")] pub top: Option, /// Exclude NSFW sites. #[arg(long)] pub no_nsfw: bool, /// Include sites disabled upstream or by self-check. #[arg(long)] pub include_disabled: bool, /// Extra site database files (WhatsMyName, Sherlock, Maigret or Percival format). #[arg(long = "db", value_name = "FILE")] pub dbs: Vec, /// Ignore the built-in databases (use only --db files). #[arg(long)] pub no_builtin: bool, /// Ignore updated copies in the data directory; use embedded data. #[arg(long)] pub embedded: bool, /// Identifier type to scan (username, email, steam_id, …). #[arg(long, value_name = "TYPE")] pub id_type: Option, } /// Network behaviour. #[derive(Args, Debug, Clone, Default)] #[command(next_help_heading = "Network")] pub struct NetArgs { /// Per-request timeout in seconds [default: 10]. #[arg(short = 't', long, value_name = "SECS")] pub timeout: Option, /// Concurrent requests [default: 60]. #[arg(short = 'j', long, value_name = "N")] pub concurrency: Option, /// Concurrent requests per host [default: 4]. #[arg(long, value_name = "N")] pub per_host: Option, /// Retries on transient failures [default: 1]. #[arg(long, value_name = "N")] pub retries: Option, /// Proxy URL (http://, socks5://, socks5h://). #[arg(long, value_name = "URL")] pub proxy: Option, /// Shortcut for --proxy socks5h://127.0.0.1:9050. #[arg(long)] pub tor: bool, /// User-Agent header. #[arg(long, value_name = "UA")] pub user_agent: Option, /// Pick a random realistic User-Agent per request. #[arg(long)] pub random_ua: bool, /// Extra header for every request ("Name: value"), repeatable. #[arg(short = 'H', long = "header", value_name = "HDR")] pub headers: Vec, /// Cookie header for every request. #[arg(long, value_name = "COOKIES")] pub cookie: Option, /// Accept invalid TLS certificates. #[arg(long)] pub insecure: bool, /// Maximum response body to read, in KiB [default: 3072]. #[arg(long, value_name = "KIB")] pub max_body_kb: Option, } #[derive(Args, Debug, Clone, Default)] pub struct ScanArgs { #[command(flatten)] pub select: SelectArgs, #[command(flatten)] pub net: NetArgs, /// Read targets from a file, one per line ("-" for stdin). #[arg(short = 'i', long, value_name = "FILE", help_heading = "Targets")] pub input: Option, /// Also search permutations of each target (john.doe → johndoe, jdoe, …). #[arg(short = 'p', long, help_heading = "Targets")] pub permute: bool, /// Aggressive permutations (numeric and word suffixes). #[arg(long, help_heading = "Targets")] pub permute_all: bool, /// Cap the number of permutations per target [default: 24]. #[arg(long, value_name = "N", help_heading = "Targets")] pub max_permutations: Option, /// Scan handles discovered on found profiles. #[arg(short = 'r', long, help_heading = "Targets")] pub recursive: bool, /// Maximum pivot depth for --recursive [default: 1]. #[arg(long, value_name = "N", help_heading = "Targets")] pub max_depth: Option, /// Skip canary verification of hits. #[arg(long, help_heading = "Analysis")] pub no_verify: bool, /// Skip profile metadata extraction. #[arg(long, help_heading = "Analysis")] pub no_extract: bool, /// Look up found profiles in the Wayback Machine. #[arg(long, help_heading = "Analysis")] pub archive: bool, /// Look up every profile URL in the Wayback Machine (finds deleted accounts). #[arg(long, help_heading = "Analysis")] pub archive_all: bool, /// Also try other databases' probes when the primary says "not found" (more requests). #[arg(long, help_heading = "Analysis")] pub thorough: bool, /// Dump raw responses into DIR. #[arg(long, value_name = "DIR", help_heading = "Analysis")] pub dump: Option, /// Print every result, including not-found sites. #[arg(short = 'a', long, help_heading = "Output")] pub print_all: bool, /// Also print blocked / errored / unknown sites. #[arg(long, help_heading = "Output")] pub print_errors: bool, /// Print only hits (alias of the default; kept for Sherlock muscle memory). #[arg(short = 'f', long = "only-found", help_heading = "Output")] pub only_found: bool, /// Hide extracted profile lines under hits. #[arg(long, help_heading = "Output")] pub no_profile: bool, /// Write reports to DIR (default: percival-reports/-