fey 0.0.2

fey is a fast and reliable username scanner
Documentation
use std::path::PathBuf;
use clap::Parser;
use fey::cli::Args;
use fey::commands::{fileoutput, scan};
use fey::utils::data::get_data_file;
use std::fs;
use fey::utils::config::ConfigFile;
use fey::utils::error::Error;


#[tokio::main]
async fn main() {

    // create config file
    let _config = match ConfigFile::new(){
        Ok(config) => config,
        Err(error) =>{
            Error::eval(error);
            std::process::exit(0x100);
        },
    };

    // unwrap is ok here because at this point we know that .config exists
    let data_file_path = dirs::config_dir().unwrap().join("fey/urls.txt");

    if !data_file_path.exists(){
        // TODO: error handling
        get_data_file(dirs::config_dir().unwrap().join("fey")).await;
    }   



    let args = Args::parse();

    // main scanner setup/runner
    // read urls.txt
    let file_content = match fs::read_to_string(data_file_path) {
        Err(error) => {
            eprintln!("Error: could not read file: {}", error);
            std::process::exit(0x100);
        }
        Ok(content) => content,
    };

    let mut output_vec: Vec<String> = vec![];

    println!("Start scanning");

    for line in file_content.lines() {
        // create full url i.e. url + username
        let full_url = line.to_string() + &args.username;

        // start scanner
        let scan_output = match scan::scan(full_url).await {
            Ok(output) => output,
            Err(error) =>{
                Error::eval(error);
                std::process::exit(0x100);
            },
        };

        print!("{}", &scan_output);
        output_vec.push(scan_output);
    }

    // if output should be written to a file
    // TODO: not working, the output is written to a file but is also printed
    if args.file.is_some() {
        let file_path = args.file.unwrap();
        fileoutput::write_to_file(PathBuf::from(file_path), output_vec);
    }
}