use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "beautiful-md")]
#[command(author, version, about, long_about = None)]
#[allow(clippy::struct_excessive_bools)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(value_name = "FILE")]
pub files: Vec<PathBuf>,
#[arg(short, long, value_name = "FILE")]
pub config: Option<PathBuf>,
#[arg(short, long)]
pub in_place: bool,
#[arg(short, long, value_name = "FILE")]
pub output: Option<PathBuf>,
#[arg(long)]
pub stdout: bool,
#[arg(short, long)]
pub glob: bool,
#[arg(short, long)]
pub verbose: bool,
#[arg(long)]
pub check: bool,
#[arg(long)]
pub dry_run: bool,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Format {
files: Vec<PathBuf>,
#[arg(short, long)]
in_place: bool,
},
Config {
#[arg(default_value = ".beautiful-md.toml")]
output: PathBuf,
},
Check {
files: Vec<PathBuf>,
},
}
impl Cli {
pub fn parse_args() -> Self {
Self::parse()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cli_parsing() {
let cli = Cli::parse_from(["beautiful-md", "test.md"]);
assert_eq!(cli.files.len(), 1);
assert!(!cli.in_place);
}
#[test]
fn test_cli_in_place() {
let cli = Cli::parse_from(["beautiful-md", "--in-place", "test.md"]);
assert!(cli.in_place);
}
}