cargo-test-filter 0.1.0

A cargo subcommand for intelligent test filtering and compilation
Documentation
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
pub struct CargoCli {
    #[command(subcommand)]
    pub command: CargoSubcommand,
}

#[derive(Subcommand, Debug)]
pub enum CargoSubcommand {
    #[command(name = "test-filter")]
    TestFilter(TestFilterArgs),
}

/// A cargo subcommand for intelligent test filtering and compilation
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct TestFilterArgs {
    /// Run only integration tests (tests in tests/ directory)
    #[arg(long, conflicts_with = "unit")]
    pub integration: bool,

    /// Run only unit tests (tests in src/ files)
    #[arg(long, conflicts_with = "integration")]
    pub unit: bool,

    /// Filter tests by tag (e.g., --tag fast or --tag "slow,integration")
    #[arg(long, value_delimiter = ',')]
    pub tag: Vec<String>,

    /// Exclude tests with these tags
    #[arg(long, value_delimiter = ',')]
    pub exclude_tag: Vec<String>,

    /// Filter tests by name pattern
    #[arg(long)]
    pub name: Option<String>,

    /// Filter tests by path pattern
    #[arg(long)]
    pub path: Option<String>,

    /// Test timeout in seconds (per test)
    #[arg(long)]
    pub timeout: Option<u64>,

    /// List matching tests without running them
    #[arg(long)]
    pub list: bool,

    /// Show verbose output
    #[arg(short, long)]
    pub verbose: bool,

    /// Arguments to pass through to cargo test
    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
    pub test_args: Vec<String>,
}

impl TestFilterArgs {
    /// Check if any filters are active
    pub fn has_filters(&self) -> bool {
        self.integration
            || self.unit
            || !self.tag.is_empty()
            || !self.exclude_tag.is_empty()
            || self.name.is_some()
            || self.path.is_some()
    }
}