1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use std::path::PathBuf;
use clap::builder::Styles;
use clap::builder::styling::{AnsiColor, Effects};
use clap::{Parser, Subcommand};
const STYLES: Styles = Styles::styled()
.header(AnsiColor::Green.on_default().effects(Effects::BOLD))
.usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
.literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
.placeholder(AnsiColor::Cyan.on_default());
#[derive(Parser)]
#[command(name = "arity")]
#[command(author, version)]
#[command(about = "Arity: a language server, formatter, and linter for R")]
#[command(styles = STYLES)]
#[command(arg_required_else_help = true)]
pub struct Cli {
/// Path to an explicit `arity.toml` (skips discovery)
#[arg(long, value_name = "PATH", global = true, conflicts_with = "no_config")]
pub config: Option<PathBuf>,
/// Ignore any discovered `arity.toml` and use built-in defaults
#[arg(long, global = true)]
pub no_config: bool,
/// When to use color in output
#[arg(long, value_enum, default_value_t = ColorChoice::Auto, global = true, value_name = "WHEN")]
pub color: ColorChoice,
/// Suppress informational output (errors are still shown)
#[arg(long, short = 'q', global = true, conflicts_with = "verbose")]
pub quiet: bool,
/// Print extra informational output (e.g. per-command summaries)
#[arg(long, short = 'v', global = true)]
pub verbose: bool,
#[command(subcommand)]
pub command: Commands,
}
/// When to colorize output.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, clap::ValueEnum)]
pub enum ColorChoice {
/// Colorize when writing to a terminal and `NO_COLOR` is unset (default).
#[default]
Auto,
/// Always colorize.
Always,
/// Never colorize.
Never,
}
#[derive(Subcommand)]
pub enum Commands {
/// Parse and display the CST tree for debugging
Parse {
/// Input file (stdin if not provided)
file: Option<PathBuf>,
/// Suppress CST output to stdout
#[arg(long)]
quiet: bool,
/// Verify parser losslessness (input must equal CST text)
#[arg(long)]
verify: bool,
},
/// Format .R files
Format {
/// Input file(s) or path(s) (stdin if omitted)
#[arg(value_name = "PATH")]
paths: Vec<PathBuf>,
/// Verify formatting idempotence for supported inputs (does not write files)
#[arg(long)]
verify: bool,
/// Check formatting without writing changes; prints a diff for each file
/// that would be reformatted and exits non-zero if any differ
#[arg(long)]
check: bool,
/// Override the configured line width
#[arg(long, value_name = "N")]
line_width: Option<u32>,
/// Override the configured indent width
#[arg(long, value_name = "N")]
indent_width: Option<u32>,
/// Additional gitignore-style exclude patterns (repeatable or
/// comma-separated); augments the configured `exclude`
#[arg(long, value_name = "PATTERN", value_delimiter = ',')]
exclude: Vec<String>,
},
/// Lint .R files
///
/// Reads stdin when no paths are given. Exit codes: 0 = no findings,
/// 1 = findings (or files blocked by parse errors), 2 = usage/IO error.
Lint {
/// Input file(s) or path(s) (stdin if omitted)
#[arg(value_name = "PATH")]
paths: Vec<PathBuf>,
/// Filename to report for stdin input (for diagnostics)
#[arg(long, value_name = "PATH")]
stdin_filename: Option<PathBuf>,
/// Apply safe autofixes in place and report what remains
#[arg(long)]
fix: bool,
/// Also apply fixes that may change behavior (requires --fix)
#[arg(long)]
unsafe_fixes: bool,
/// Only run these rules (overrides config `select`); repeatable or comma-separated
#[arg(long, value_name = "RULE_ID", value_delimiter = ',')]
select: Vec<String>,
/// Disable these rules (overrides config `ignore`); repeatable or comma-separated
#[arg(long, value_name = "RULE_ID", value_delimiter = ',')]
ignore: Vec<String>,
/// Additional gitignore-style exclude patterns (repeatable or
/// comma-separated); augments the configured `exclude`
#[arg(long, value_name = "PATTERN", value_delimiter = ',')]
exclude: Vec<String>,
/// Output format
#[arg(long, value_enum, default_value_t = LintOutput::Pretty)]
output: LintOutput,
},
/// Build or refresh the installed-package introspection index
Index {
/// Project path(s) to scan for referenced packages (default: ".")
#[arg(value_name = "PATH")]
paths: Vec<PathBuf>,
/// Re-harvest even when the installed version is already indexed
#[arg(long)]
force: bool,
/// Skip harvesting help (names only; faster)
#[arg(long)]
no_help: bool,
/// Override the cache directory
#[arg(long, value_name = "DIR")]
cache_dir: Option<PathBuf>,
/// Suppress per-package progress output
#[arg(long)]
quiet: bool,
},
/// Run the language server over stdio
Lsp,
/// Generate a shell completion script (write it to stdout)
Completions {
/// Shell to generate completions for
#[arg(value_enum)]
shell: clap_complete::Shell,
},
/// Write a starter `arity.toml` to the current directory
Init {
/// Overwrite an existing `arity.toml`
#[arg(long)]
force: bool,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum LintOutput {
/// Annotated multi-line snippets (default; matches jarl/rustc-style output).
Pretty,
/// One finding per line (`path:line:col: severity [rule] message`).
Concise,
/// JSON array of diagnostics, for editor integration.
Json,
}