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    /// Display project information
37    About,
38    /// Check for updates and install the latest version
39    Update {
40        /// Only check for available updates without installing
41        #[arg(long)]
42        check: bool,
43    },
44}
45
46#[derive(Debug, clap::Args)]
47pub struct AnalyzeArgs {
48    /// Files or directories to analyze
49    #[arg()]
50    pub paths: Vec<PathBuf>,
51
52    /// Output format
53    #[arg(long, default_value = "table")]
54    pub format: OutputFormat,
55
56    /// Language for stdin input (required when piping)
57    #[arg(long)]
58    pub language: Option<String>,
59
60    /// Cognitive complexity threshold
61    #[arg(long)]
62    pub threshold: Option<u64>,
63
64    /// Show only functions exceeding the threshold
65    #[arg(long)]
66    pub exceeds_only: bool,
67
68    /// Sort results by metric
69    #[arg(long)]
70    pub sort: Option<SortMetric>,
71
72    /// Show only the top N results
73    #[arg(long)]
74    pub top: Option<usize>,
75
76    /// Filter directory traversal by language (comma-separated)
77    #[arg(long, value_delimiter = ',')]
78    pub languages: Option<Vec<String>>,
79
80    /// Respect .gitignore patterns during directory traversal
81    #[arg(long)]
82    pub gitignore: bool,
83
84    /// Exclude method-level analysis
85    #[arg(long)]
86    pub no_methods: bool,
87}