use ::clap::Parser;
use regex::Regex;
use crate::common::CommandArgs;
#[derive(Parser, Debug, Clone)]
#[command(
name = "batched",
about = "Split stdin into groups of N lines, and pass them to the command"
)]
pub struct BatchedArgs {
#[arg(short = 'c', long, value_parser = clap::value_parser!(u32).range(2..))]
pub batch_size: u32,
#[arg(long)]
pub together: Option<Regex>,
#[arg(long, conflicts_with = "together")]
pub apart: Option<Regex>,
#[arg(long)]
pub mixed_groups: bool,
#[arg(long)]
pub drop_unmatched: bool,
#[command(subcommand)]
pub cmd: CommandArgs,
}
#[test]
fn test_cli_args() {
BatchedArgs::try_parse_from(&["batched", "-c=2", "wc", "-l"]).unwrap();
BatchedArgs::try_parse_from(&[
"batched",
"-c=2",
"--apart",
"nr([0-9]+)",
"--mixed-groups",
"implode",
])
.unwrap();
BatchedArgs::try_parse_from(&["batched", "-c=2", "--together", "^\\w+", "implode"]).unwrap();
}