loq_cli/
cli.rs

1//! CLI argument definitions.
2
3use std::path::PathBuf;
4
5use clap::{Args, Parser, Subcommand};
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    /// Accept defeat for currently failing files.
30    AcceptDefeat(AcceptDefeatArgs),
31}
32
33/// Arguments for the check command.
34#[derive(Args, Debug, Clone)]
35pub struct CheckArgs {
36    /// Paths to check (files, directories, or - for stdin).
37    #[arg(value_name = "PATH", allow_hyphen_values = true)]
38    pub paths: Vec<PathBuf>,
39
40    /// Disable file caching.
41    #[arg(long = "no-cache")]
42    pub no_cache: bool,
43}
44
45/// Arguments for the init command.
46#[derive(Args, Debug, Clone)]
47pub struct InitArgs {}
48
49/// Arguments for the baseline command.
50#[derive(Args, Debug, Clone)]
51pub struct BaselineArgs {
52    /// Line threshold for baseline (defaults to `default_max_lines` from config).
53    #[arg(long = "threshold")]
54    pub threshold: Option<usize>,
55
56    /// Allow increasing limits for files that grew beyond their baseline.
57    #[arg(long = "allow-growth")]
58    pub allow_growth: bool,
59}
60
61/// Arguments for the accept-defeat command.
62#[derive(Args, Debug, Clone)]
63pub struct AcceptDefeatArgs {
64    /// Specific files to accept defeat on.
65    #[arg(value_name = "FILE")]
66    pub files: Vec<PathBuf>,
67
68    /// Extra lines to add above the current line count.
69    #[arg(long = "buffer", default_value_t = 100)]
70    pub buffer: usize,
71}