repositories

percival

Follow the trail a handle leaves across the web: username search across 5,700+ sites, in Rust

clonegit clone https://git.daemon-sec.xyz/percival.git
mod.rsRust31 lines942 Braw download
//! Command implementations.

pub mod misc;
pub mod search;
pub mod sites;

use std::path::PathBuf;

use anyhow::{Context, Result};

/// Read targets from a file (or stdin when the path is `-`), one per line.
pub fn read_targets_file(path: &PathBuf) -> Result<Vec<String>> {
    let text = if path.as_os_str() == "-" {
        let mut s = String::new();
        std::io::Read::read_to_string(&mut std::io::stdin(), &mut s).context("reading stdin")?;
        s
    } else {
        std::fs::read_to_string(path).with_context(|| format!("reading {}", path.display()))?
    };
    Ok(text
        .lines()
        .map(|l| l.trim().to_string())
        .filter(|l| !l.is_empty() && !l.starts_with('#'))
        .collect())
}

/// Exit codes: 0 hits, 1 no hits, 2 usage/config error, 3 nothing answered (network down).
pub const EXIT_HITS: i32 = 0;
pub const EXIT_NO_HITS: i32 = 1;
pub const EXIT_USAGE: i32 = 2;
pub const EXIT_NETWORK: i32 = 3;