Skip to main content

arborist_cli/
cli.rs

1use std::path::PathBuf;
2
3use clap::{Parser, Subcommand, ValueEnum};
4
5#[derive(Debug, Clone, ValueEnum)]
6pub enum OutputFormat {
7    Table,
8    Json,
9    Csv,
10}
11
12#[derive(Debug, Clone, ValueEnum)]
13pub enum SortMetric {
14    Cognitive,
15    Cyclomatic,
16    Sloc,
17    Name,
18}
19
20#[derive(Debug, Parser)]
21#[command(
22    name = "arborist",
23    version,
24    about = "Code complexity metrics powered by arborist-metrics"
25)]
26pub struct Cli {
27    #[command(subcommand)]
28    pub command: Option<Command>,
29
30    #[command(flatten)]
31    pub analyze: AnalyzeArgs,
32}
33
34#[derive(Debug, Subcommand)]
35pub enum Command {
36    /// Check for updates and install the latest version
37    Update {
38        /// Only check for available updates without installing
39        #[arg(long)]
40        check: bool,
41    },
42}
43
44#[derive(Debug, clap::Args)]
45pub struct AnalyzeArgs {
46    /// Files or directories to analyze
47    #[arg()]
48    pub paths: Vec<PathBuf>,
49
50    /// Output format
51    #[arg(long, default_value = "table")]
52    pub format: OutputFormat,
53
54    /// Language for stdin input (required when piping)
55    #[arg(long)]
56    pub language: Option<String>,
57
58    /// Cognitive complexity threshold
59    #[arg(long)]
60    pub threshold: Option<u64>,
61
62    /// Show only functions exceeding the threshold
63    #[arg(long)]
64    pub exceeds_only: bool,
65
66    /// Sort results by metric
67    #[arg(long)]
68    pub sort: Option<SortMetric>,
69
70    /// Show only the top N results
71    #[arg(long)]
72    pub top: Option<usize>,
73
74    /// Filter directory traversal by language (comma-separated)
75    #[arg(long, value_delimiter = ',')]
76    pub languages: Option<Vec<String>>,
77
78    /// Respect .gitignore patterns during directory traversal
79    #[arg(long)]
80    pub gitignore: bool,
81
82    /// Exclude method-level analysis
83    #[arg(long)]
84    pub no_methods: bool,
85}