use crate::commands;
use clap::Subcommand;
#[derive(Subcommand)]
pub enum CoreCommands {
Validate {
#[arg(value_name = "FILE")]
file: String,
#[arg(short, long)]
strict: bool,
#[arg(short, long)]
lenient: bool,
},
Format {
#[arg(value_name = "FILE")]
file: String,
#[arg(short, long)]
output: Option<String>,
#[arg(short, long)]
check: bool,
#[arg(long, default_value = "true")]
ditto: bool,
#[arg(long)]
with_counts: bool,
},
Lint {
#[arg(value_name = "FILE")]
file: String,
#[arg(short, long, default_value = "text")]
format: String,
#[arg(short = 'W', long)]
warn_error: bool,
},
Inspect {
#[arg(value_name = "FILE")]
file: String,
#[arg(short, long)]
verbose: bool,
},
Stats {
#[arg(value_name = "FILE")]
file: String,
#[arg(short, long)]
tokens: bool,
},
}
impl CoreCommands {
pub fn execute(self) -> Result<(), crate::error::CliError> {
match self {
CoreCommands::Validate {
file,
strict,
lenient,
} => commands::validate(&file, strict, lenient),
CoreCommands::Format {
file,
output,
check,
ditto,
with_counts,
} => commands::format(&file, output.as_deref(), check, ditto, with_counts),
CoreCommands::Lint {
file,
format,
warn_error,
} => commands::lint(&file, &format, warn_error),
CoreCommands::Inspect { file, verbose } => commands::inspect(&file, verbose),
CoreCommands::Stats { file, tokens } => commands::stats(&file, tokens),
}
}
}