loq_cli/
cli.rs

1//! CLI argument definitions.
2
3use std::path::PathBuf;
4
5use clap::{Args, Parser, Subcommand, ValueEnum};
6
7/// Parsed command-line arguments.
8#[derive(Parser, Debug)]
9#[command(name = "loq", version, about = "Enforce file size constraints")]
10pub struct Cli {
11    /// Subcommand to run.
12    #[command(subcommand)]
13    pub command: Option<Command>,
14
15    /// Show extra information.
16    #[arg(short = 'v', long = "verbose", global = true)]
17    pub verbose: bool,
18}
19
20/// Available commands.
21#[derive(Subcommand, Debug, Clone)]
22pub enum Command {
23    /// Check file line counts.
24    Check(CheckArgs),
25    /// Create a loq.toml config file.
26    Init(InitArgs),
27    /// Update baseline rules for files exceeding the limit.
28    Baseline(BaselineArgs),
29    /// Relax limits for currently failing files.
30    Relax(RelaxArgs),
31}
32
33/// Output format for check results.
34#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
35pub enum OutputFormat {
36    /// Human-readable colored output.
37    #[default]
38    Text,
39    /// Machine-readable JSON output.
40    Json,
41}
42
43/// Arguments for the check command.
44#[derive(Args, Debug, Clone)]
45pub struct CheckArgs {
46    /// Paths to check (files, directories, or - for stdin).
47    #[arg(value_name = "PATH", allow_hyphen_values = true)]
48    pub paths: Vec<PathBuf>,
49
50    /// Disable file caching.
51    #[arg(long = "no-cache")]
52    pub no_cache: bool,
53
54    /// Output format.
55    #[arg(long = "output-format", value_enum, default_value_t = OutputFormat::Text)]
56    pub output_format: OutputFormat,
57}
58
59/// Arguments for the init command.
60#[derive(Args, Debug, Clone)]
61pub struct InitArgs {}
62
63/// Arguments for the baseline command.
64#[derive(Args, Debug, Clone)]
65pub struct BaselineArgs {
66    /// Line threshold for baseline (defaults to `default_max_lines` from config).
67    #[arg(long = "threshold")]
68    pub threshold: Option<usize>,
69
70    /// Allow increasing limits for files that grew beyond their baseline.
71    #[arg(long = "allow-growth")]
72    pub allow_growth: bool,
73}
74
75/// Arguments for the relax command.
76#[derive(Args, Debug, Clone)]
77pub struct RelaxArgs {
78    /// Specific files to relax limits for.
79    #[arg(value_name = "FILE")]
80    pub files: Vec<PathBuf>,
81
82    /// Extra lines to add above the current line count.
83    #[arg(long = "buffer", default_value_t = 100)]
84    pub buffer: usize,
85}