//! 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<Command>,
/// Usernames to search (default command).
#[arg(value_name = "USERNAME")]
pub targets: Vec<String>,
#[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<String>,
/// Config file (default: ~/.config/percival/config.toml).
#[arg(long, global = true, value_name = "FILE")]
pub config: Option<PathBuf>,
/// Data directory for updated databases and self-check overlay.
#[arg(long, global = true, value_name = "DIR")]
pub data_dir: Option<PathBuf>,
}
#[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<String>,
#[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<String>,
/// 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<String>,
#[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<String>,
/// Only sites carrying a tag (Maigret tags, country codes like "ru", "engine:discourse").
#[arg(long, value_delimiter = ',', value_name = "TAG")]
pub tag: Vec<String>,
/// Only sites whose name or host contains this text (comma separated).
#[arg(short = 's', long = "site", value_delimiter = ',', value_name = "NAME")]
pub sites: Vec<String>,
/// Skip sites whose name or host contains this text.
#[arg(
short = 'x',
long = "exclude",
value_delimiter = ',',
value_name = "NAME"
)]
pub exclude: Vec<String>,
/// Only these databases: wmn, sherlock, maigret, percival, custom.
#[arg(long, value_delimiter = ',', value_name = "SRC")]
pub source: Vec<String>,
/// Filter expression, e.g. "cat=social and not protection~cloudflare".
#[arg(short = 'F', long, value_name = "EXPR")]
pub filter: Option<String>,
/// 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<usize>,
/// 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<PathBuf>,
/// 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<String>,
}
/// 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<f64>,
/// Concurrent requests [default: 60].
#[arg(short = 'j', long, value_name = "N")]
pub concurrency: Option<usize>,
/// Concurrent requests per host [default: 4].
#[arg(long, value_name = "N")]
pub per_host: Option<usize>,
/// Retries on transient failures [default: 1].
#[arg(long, value_name = "N")]
pub retries: Option<u32>,
/// Proxy URL (http://, socks5://, socks5h://).
#[arg(long, value_name = "URL")]
pub proxy: Option<String>,
/// 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<String>,
/// 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<String>,
/// Cookie header for every request.
#[arg(long, value_name = "COOKIES")]
pub cookie: Option<String>,
/// 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<usize>,
}
#[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<PathBuf>,
/// 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<usize>,
/// 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<u8>,
/// 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<PathBuf>,
/// 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/<target>-<time>).
#[arg(short = 'o', long, value_name = "DIR", num_args = 0..=1, default_missing_value = "", help_heading = "Output")]
pub output: Option<String>,
/// Report formats: html, json, ndjson, csv, md, txt, dot, all [default: html,json,csv].
#[arg(
long,
value_delimiter = ',',
value_name = "FMT",
help_heading = "Output"
)]
pub formats: Vec<String>,
/// Stream NDJSON events to stdout (no banner or progress).
#[arg(long, help_heading = "Output")]
pub json: bool,
/// Disable the progress bar.
#[arg(long, help_heading = "Output")]
pub no_progress: bool,
/// Open found profiles in the browser.
#[arg(long, help_heading = "Output")]
pub browse: bool,
}
#[derive(Args, Debug, Clone, Default)]
pub struct SitesArgs {
#[command(flatten)]
pub select: SelectArgs,
/// Show full details for one site (by name).
#[arg(long, value_name = "NAME")]
pub show: Option<String>,
/// Print counts per source and category instead of the list.
#[arg(long)]
pub stats: bool,
/// Print the profile URL each site would check for USERNAME.
#[arg(long, value_name = "USERNAME")]
pub urls: Option<String>,
/// Output JSON.
#[arg(long)]
pub json: bool,
}
#[derive(Args, Debug, Clone, Default)]
pub struct SelfcheckArgs {
#[command(flatten)]
pub select: SelectArgs,
#[command(flatten)]
pub net: NetArgs,
/// Write broken sites into the disabled overlay (and re-enable fixed ones).
#[arg(long)]
pub write: bool,
/// Only print sites that are not healthy.
#[arg(long)]
pub problems: bool,
/// Output JSON.
#[arg(long)]
pub json: bool,
}
#[derive(Args, Debug, Clone, Default)]
pub struct UpdateArgs {
/// Databases to refresh [default: wmn,sherlock,maigret].
#[arg(long, value_delimiter = ',', value_name = "SRC")]
pub source: Vec<String>,
/// Show cache status without downloading.
#[arg(long)]
pub status: bool,
/// Delete cached copies (fall back to embedded data).
#[arg(long)]
pub clear: bool,
#[command(flatten)]
pub net: NetArgs,
}
#[derive(Args, Debug, Clone, Default)]
pub struct PermuteArgs {
/// Names to permute.
#[arg(value_name = "NAME", required = true)]
pub names: Vec<String>,
/// Aggressive permutations.
#[arg(long)]
pub all: bool,
/// Maximum permutations per name [default: 64].
#[arg(long, value_name = "N")]
pub max: Option<usize>,
}
#[derive(Args, Debug, Clone, Default)]
pub struct ParseArgs {
/// Profile URLs.
#[arg(value_name = "URL", required = true)]
pub urls: Vec<String>,
/// Fetch each page and extract profile data and handles from its content.
#[arg(long)]
pub fetch: bool,
/// Output JSON.
#[arg(long)]
pub json: bool,
#[command(flatten)]
pub net: NetArgs,
}
#[derive(Args, Debug, Clone, Default)]
pub struct ConfigArgs {
/// Write a commented template config file if none exists.
#[arg(long)]
pub init: bool,
/// Print the config file path only.
#[arg(long)]
pub path: bool,
}
#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum ThemeName {
RosePine,
RosePineMoon,
RosePineDawn,
None,
}