use clap::{Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(
name = "fy",
about = "Fast YAML processor with validation and linting",
version,
author,
long_about = None
)]
#[allow(clippy::struct_excessive_bools)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
#[arg(short = 'i', long, global = true)]
pub in_place: bool,
#[arg(short, long, global = true, value_name = "FILE")]
pub output: Option<PathBuf>,
#[arg(short = 'f', long, value_enum, default_value = "yaml")]
pub format: OutputFormat,
#[arg(long, global = true)]
pub no_color: bool,
#[arg(short, long, global = true)]
pub quiet: bool,
#[arg(short, long, global = true)]
pub verbose: bool,
}
#[derive(Subcommand, Debug)]
pub enum Command {
Parse {
file: Option<PathBuf>,
#[arg(long)]
stats: bool,
},
Format {
#[arg(value_name = "PATHS")]
paths: Vec<PathBuf>,
#[arg(long, default_value = "2", value_parser = clap::value_parser!(u8).range(2..=8))]
indent: u8,
#[arg(long, default_value = "80")]
width: usize,
#[arg(short = 'j', long, default_value = "0")]
jobs: usize,
#[arg(long, conflicts_with = "paths")]
stdin_files: bool,
#[arg(long)]
include: Vec<String>,
#[arg(long)]
exclude: Vec<String>,
#[arg(long)]
no_recursive: bool,
#[arg(short = 'n', long)]
dry_run: bool,
},
Convert {
#[arg(value_enum)]
to: ConvertFormat,
file: Option<PathBuf>,
#[arg(long, default_value_t = true, num_args = 0..=1, default_missing_value = "true", action = clap::ArgAction::Set)]
pretty: bool,
},
#[cfg(feature = "linter")]
Lint {
file: Option<PathBuf>,
#[arg(long, default_value = "120")]
max_line_length: usize,
#[arg(long, default_value = "2")]
indent_size: usize,
#[arg(long, value_enum, default_value = "text")]
format: LintFormat,
#[arg(long)]
allow_duplicate_keys: bool,
},
}
#[derive(ValueEnum, Clone, Debug)]
pub enum OutputFormat {
Yaml,
Json,
Compact,
}
#[derive(ValueEnum, Clone, Debug)]
pub enum ConvertFormat {
Yaml,
Json,
}
#[cfg(feature = "linter")]
#[derive(ValueEnum, Clone, Debug)]
pub enum LintFormat {
Text,
Json,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert();
}
}