maskit 0.1.1

A CLI tool to mask sensitive fields in configuration files (JSON/YAML/TOML)
Documentation
use clap::Parser;
use colored::*;
use std::path::PathBuf;
use std::process;

use maskit::{error::MaskitError, MaskitProcessor};

#[derive(Parser)]
#[command(
    name = "maskit",
    version,
    about = "A CLI tool to mask sensitive fields in configuration files",
    long_about = "Maskit helps you safely share configuration files by masking sensitive fields like API keys and secrets"
)]
struct Cli {
    /// Input configuration file path
    input: PathBuf,

    /// Output file path (default: adds .maskit before extension)
    #[arg(short, long)]
    output: Option<PathBuf>,

    /// Keywords to search for in field names (default: key, secret)
    #[arg(
        short,
        long,
        value_delimiter = ',',
        default_value = "key,secret,password,token,credential,auth,private,cert"
    )]
    keywords: Vec<String>,

    /// Silent mode - suppress all output
    #[arg(short, long)]
    silent: bool,
}

fn main() {
    let args = Cli::parse();

    let processor = MaskitProcessor::new(args.input, args.output, args.keywords);

    if let Err(e) = processor.process(args.silent) {
        if !args.silent {
            print_error(&e);
        }
        process::exit(1);
    }
}

fn print_error(error: &MaskitError) {
    eprintln!("{} {}", "❌ Error:".red().bold(), error);

    // Provide helpful suggestions based on the error type
    match error {
        MaskitError::FileRead(_) => {
            eprintln!(
                "{}",
                "💡 Please check if the file exists and you have read permissions.".yellow()
            );
        }
        MaskitError::FileWrite(_) => {
            eprintln!(
                "{}",
                "💡 Please check if you have write permissions in the target directory.".yellow()
            );
        }
        MaskitError::UnsupportedFormat(ext) => {
            eprintln!("{} JSON, YAML, TOML", "💡 Supported formats:".yellow());
            eprintln!("{} {}", "   File extension detected:".yellow(), ext);
        }
        MaskitError::ParseError { format, .. } => {
            eprintln!("{} {}", "💡 Please check if your".yellow(), format);
            eprintln!("{}", "   file is valid and properly formatted.".yellow());
        }
        _ => {}
    }
}