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, directories, or - for stdin).
49    #[arg(value_name = "PATH", allow_hyphen_values = true)]
50    pub paths: Vec<PathBuf>,
51
52    /// Disable file caching.
53    #[arg(long = "no-cache")]
54    pub no_cache: bool,
55
56    /// Output format.
57    #[arg(long = "output-format", value_enum, default_value_t = OutputFormat::Text)]
58    pub output_format: OutputFormat,
59}
60
61/// Arguments for the init command.
62#[derive(Args, Debug, Clone)]
63pub struct InitArgs {}
64
65/// Arguments for the baseline command.
66#[derive(Args, Debug, Clone)]
67pub struct BaselineArgs {
68    /// Line threshold for baseline (defaults to `default_max_lines` from config).
69    #[arg(long = "threshold")]
70    pub threshold: Option<usize>,
71}
72
73/// Arguments for the tighten command.
74#[derive(Args, Debug, Clone)]
75pub struct TightenArgs {
76    /// Line threshold for tightening (defaults to `default_max_lines` from config).
77    #[arg(long = "threshold")]
78    pub threshold: Option<usize>,
79}
80
81/// Arguments for the relax command.
82#[derive(Args, Debug, Clone)]
83pub struct RelaxArgs {
84    /// Specific files to relax limits for.
85    #[arg(value_name = "FILE")]
86    pub files: Vec<PathBuf>,
87
88    /// Extra lines to add above the current line count.
89    #[arg(long = "extra", visible_alias = "buffer", default_value_t = 0)]
90    pub extra: usize,
91}