use crate::commands;
use clap::Subcommand;
#[derive(Subcommand)]
pub enum BatchCommands {
BatchValidate {
#[arg(value_name = "FILES", num_args = 1..)]
files: Vec<String>,
#[arg(short, long)]
strict: bool,
#[arg(short, long)]
parallel: bool,
#[arg(short, long)]
verbose: bool,
#[arg(long)]
streaming: bool,
#[arg(long)]
auto_streaming: bool,
#[arg(long)]
max_files: Option<usize>,
},
BatchFormat {
#[arg(value_name = "FILES", num_args = 1..)]
files: Vec<String>,
#[arg(short, long)]
output_dir: Option<String>,
#[arg(short, long)]
check: bool,
#[arg(long, default_value = "true")]
ditto: bool,
#[arg(long)]
with_counts: bool,
#[arg(short, long)]
parallel: bool,
#[arg(short, long)]
verbose: bool,
#[arg(long)]
max_files: Option<usize>,
},
BatchLint {
#[arg(value_name = "FILES", num_args = 1..)]
files: Vec<String>,
#[arg(short = 'W', long)]
warn_error: bool,
#[arg(short, long)]
parallel: bool,
#[arg(short, long)]
verbose: bool,
#[arg(long)]
max_files: Option<usize>,
},
}
impl BatchCommands {
pub fn execute(self) -> Result<(), crate::error::CliError> {
fn convert_max_files(max_files: Option<usize>) -> Option<Option<usize>> {
max_files.map(|n| if n == 0 { None } else { Some(n) })
}
match self {
BatchCommands::BatchValidate {
files,
strict,
parallel,
verbose,
streaming: _,
auto_streaming: _,
max_files,
} => commands::batch_validate_with_config(
files,
strict,
false,
100,
parallel,
verbose,
convert_max_files(max_files),
),
BatchCommands::BatchFormat {
files,
output_dir,
check,
ditto,
with_counts,
parallel,
verbose,
max_files,
} => commands::batch_format_with_config(commands::BatchFormatParams {
patterns: files,
output_dir,
check,
ditto,
with_counts,
recursive: false,
max_depth: 100,
parallel,
verbose,
max_files_override: convert_max_files(max_files),
}),
BatchCommands::BatchLint {
files,
warn_error,
parallel,
verbose,
max_files,
} => commands::batch_lint_with_config(
files,
warn_error,
false,
100,
parallel,
verbose,
convert_max_files(max_files),
),
}
}
}