Skip to main content

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    /// Reset baseline limits to match current file sizes.
28    Baseline(BaselineArgs),
29    /// Tighten baseline limits without raising them.
30    Tighten(TightenArgs),
31    /// Allow violations by raising their limits.
32    Relax(RelaxArgs),
33}
34
35/// Output format for check results.
36#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
37pub enum OutputFormat {
38    /// Human-readable colored output.
39    #[default]
40    Text,
41    /// Machine-readable JSON output.
42    Json,
43}
44
45/// Arguments for the check command.
46#[derive(Args, Debug, Clone)]
47pub struct CheckArgs {
48    /// Paths to check (files or directories).
49    #[arg(value_name = "PATH", conflicts_with_all = ["staged", "diff"])]
50    pub paths: Vec<PathBuf>,
51
52    /// Read additional paths from stdin (internal flag used for `loq check -`).
53    #[arg(long = "stdin", hide = true, conflicts_with_all = ["staged", "diff"])]
54    pub stdin: bool,
55
56    /// Check only files currently staged in git.
57    #[arg(long = "staged", conflicts_with = "diff")]
58    pub staged: bool,
59
60    /// Check files changed since a git reference.
61    #[arg(long = "diff", value_name = "REF", conflicts_with = "staged")]
62    pub diff: Option<String>,
63
64    /// Disable file caching.
65    #[arg(long = "no-cache")]
66    pub no_cache: bool,
67
68    /// Output format.
69    #[arg(long = "output-format", value_enum, default_value_t = OutputFormat::Text)]
70    pub output_format: OutputFormat,
71}
72
73/// Arguments for the init command.
74#[derive(Args, Debug, Clone)]
75pub struct InitArgs {}
76
77/// Arguments for the baseline command.
78#[derive(Args, Debug, Clone)]
79pub struct BaselineArgs {
80    /// Line threshold for baseline (defaults to `default_max_lines` from config).
81    #[arg(long = "threshold")]
82    pub threshold: Option<usize>,
83}
84
85/// Arguments for the tighten command.
86#[derive(Args, Debug, Clone)]
87pub struct TightenArgs {
88    /// Line threshold for tightening (defaults to `default_max_lines` from config).
89    #[arg(long = "threshold")]
90    pub threshold: Option<usize>,
91}
92
93/// Arguments for the relax command.
94#[derive(Args, Debug, Clone)]
95pub struct RelaxArgs {
96    /// Specific files to relax limits for.
97    #[arg(value_name = "FILE")]
98    pub files: Vec<PathBuf>,
99
100    /// Extra lines to add above the current line count.
101    #[arg(long = "extra", visible_alias = "buffer", default_value_t = 0)]
102    pub extra: usize,
103}