use std::path::PathBuf;
use std::process::ExitCode;
use clap::{Args, Parser, Subcommand, ValueEnum};
use crate::commands;
#[derive(Debug, Parser)]
#[command(name = "rpm-spec-tool", version, about)]
pub struct Application {
#[command(subcommand)]
pub command: Command,
#[arg(long, global = true, default_value_t = ColorChoice::Auto, value_enum)]
pub color: ColorChoice,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
#[clap(rename_all = "lower")]
pub enum ColorChoice {
Auto,
Always,
Never,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Lint(commands::lint::Cmd),
Format(commands::format::Cmd),
Pretty(commands::pretty::Cmd),
Ast(commands::ast::Cmd),
Check(commands::check::Cmd),
Profile(commands::profile::Cmd),
Lints(commands::lints::Cmd),
Completions(commands::completions::Cmd),
}
#[derive(Debug, Args)]
pub struct CommonInput {
pub paths: Vec<PathBuf>,
#[arg(long, global = true)]
pub config: Option<PathBuf>,
}
#[derive(Debug, Args, Default, Clone)]
pub struct MacroDefinesArg {
#[arg(long = "define", short = 'D', value_name = "NAME VALUE")]
pub raw: Vec<String>,
}
impl Application {
pub fn run(self) -> anyhow::Result<ExitCode> {
let color = self.color;
match self.command {
Command::Lint(cmd) => cmd.run(color),
Command::Format(cmd) => cmd.run(color),
Command::Pretty(cmd) => cmd.run(color),
Command::Ast(cmd) => cmd.run(),
Command::Check(cmd) => cmd.run(color),
Command::Profile(cmd) => cmd.run(color),
Command::Lints(cmd) => cmd.run(color),
Command::Completions(cmd) => cmd.run(),
}
}
}