compare-changes 0.8.5

Reimplementation of GitHub file paths pattern matcher
Documentation
use clap::Parser;
use std::path::PathBuf;

mod style;
use style::get_style;

#[derive(Parser)]
#[command(
    version,
    about = "Compare wildcard paths to changed files, or detect changed files from GitHub event context with --find.",
    styles = get_style()
)]
pub struct Args {
    /// Find changed files from the git diff base inferred from GitHub Actions event context
    #[arg(short, long, default_value_t = false, conflicts_with_all = ["wildcard", "changes"])]
    pub find: bool,

    /// Wildcard name, * in .github/workflows/wildcard-*
    #[arg(short, long, value_name = "FILE", required_unless_present = "find")]
    pub wildcard: Option<PathBuf>,

    /// JSON array string, for example '["foo/bar", "baz"]'
    #[arg(short, long, value_name = "JSON", required_unless_present = "find")]
    pub changes: Option<String>,

    /// Enable debug output
    #[arg(short, long)]
    pub debug: bool,
}

pub fn parse_args() -> Args {
    let mut args = Args::parse();

    if let Some(wildcard) = args.wildcard.take() {
        // Apply the prefix transformation to wildcard
        let prefixed = PathBuf::from(".github/workflows").join(format!("wildcard-{}", wildcard.display()));
        args.wildcard = Some(prefixed);
    }

    args
}