code complexity & repetition analysis tool
1# CLI Reference
2
3## Commands
4
5### `analyze`
6
7Run full analysis (complexity + clones + LOC).
8
9```bash
10mccabre analyze [OPTIONS] [PATH]
11```
12
13**Arguments:**
14
15- `[PATH]` - Path to file or directory (default: `.`)
16
17**Options:**
18
19- `-j, --json` - Output in JSON format
20- `--threshold <N>` - Complexity warning threshold
21- `--min-tokens <N>` - Minimum tokens for clone detection (default: 30)
22- `-c, --config <FILE>` - Path to config file
23- `--no-gitignore` - Disable gitignore awareness
24- `--no-highlight` - Disable syntax highlighting for code blocks
25
26**Examples:**
27
28```bash
29# Analyze current directory
30mccabre analyze
31
32# Analyze specific path with JSON output
33mccabre analyze ./src --json
34
35# Custom thresholds
36mccabre analyze ./src --threshold 15 --min-tokens 25
37```
38
39### `complexity`
40
41Analyze cyclomatic complexity and LOC only.
42
43```bash
44mccabre complexity [OPTIONS] [PATH]
45```
46
47**Arguments:**
48
49- `[PATH]` - Path to file or directory (default: `.`)
50
51**Options:**
52
53- `-j, --json` - Output in JSON format
54- `--threshold <N>` - Complexity warning threshold
55- `-c, --config <FILE>` - Path to config file
56- `--no-gitignore` - Disable gitignore awareness
57
58**Examples:**
59
60```bash
61# Check complexity of src/
62mccabre complexity src/
63
64# Fail if any file exceeds complexity of 20
65mccabre complexity src/ --threshold 20
66```
67
68### `clones`
69
70Detect code clones only.
71
72```bash
73mccabre clones [OPTIONS] [PATH]
74```
75
76**Arguments:**
77
78- `[PATH]` - Path to file or directory (default: `.`)
79
80**Options:**
81
82- `-j, --json` - Output in JSON format
83- `--min-tokens <N>` - Minimum tokens for detection (default: 30)
84- `-c, --config <FILE>` - Path to config file
85- `--no-gitignore` - Disable gitignore awareness
86- `--no-highlight` - Disable syntax highlighting for code blocks
87
88**Examples:**
89
90```bash
91# Find clones in current directory
92mccabre clones .
93
94# Find only large clones (50+ tokens)
95mccabre clones . --min-tokens 50
96
97# JSON output for processing
98mccabre clones src/ --json | jq '.clones | length'
99```
100
101### `dump-config`
102
103Display and optionally save current configuration.
104
105```bash
106mccabre dump-config [OPTIONS]
107```
108
109**Options:**
110
111- `-c, --config <FILE>` - Path to config file (shows default if not specified)
112- `-o, --output <PATH>` - Save configuration to file or directory
113
114**Examples:**
115
116```bash
117# Show default configuration
118mccabre dump-config
119
120# Show loaded configuration
121mccabre dump-config --config mccabre.toml
122
123# Save default config to file
124mccabre dump-config -o my-config.toml
125
126# Save config to directory (creates mccabre.toml)
127mccabre dump-config -o ./configs/
128
129# Load and save to new location
130mccabre dump-config -c old-config.toml -o new-config.toml
131```
132
133## Global Options
134
135### `-h, --help`
136
137Show help information.
138
139```bash
140mccabre --help
141mccabre analyze --help
142```
143
144### `-V, --version`
145
146Show version information.
147
148```bash
149mccabre --version
150```
151
152## Output Formats
153
154### Terminal (Default)
155
156Colored, human-readable output:
157
158```text
159FILE: src/main.rs
160 Cyclomatic Complexity: 15 (warning)
161 Physical LOC: 120
162 Logical LOC: 85
163```
164
165Colors:
166
167- **Green**: Low/good
168- **Yellow**: Moderate/warning
169- **Red**: High/error
170
171### JSON
172
173Machine-readable output for CI/CD:
174
175```bash
176mccabre analyze src/ --json
177```
178
179```json
180{
181 "files": [
182 {
183 "path": "src/main.rs",
184 "loc": {
185 "physical": 120,
186 "logical": 85,
187 "comments": 25,
188 "blank": 10
189 },
190 "cyclomatic": {
191 "file_complexity": 15,
192 "functions": []
193 }
194 }
195 ],
196 "clones": [],
197 "summary": {
198 "total_files": 1,
199 "total_physical_loc": 120,
200 "total_logical_loc": 85,
201 "avg_complexity": 15.0,
202 "max_complexity": 15,
203 "high_complexity_files": 1,
204 "total_clones": 0
205 }
206}
207```
208
209## File Selection
210
211### Supported Languages
212
213- **Rust**: `.rs`
214- **JavaScript**: `.js`, `.jsx`, `.mjs`, `.cjs`
215- **TypeScript**: `.ts`, `.tsx`
216- **Go**: `.go`
217- **Java**: `.java`
218- **C++**: `.cpp`, `.cc`, `.cxx`, `.h`, `.hpp`, `.hxx`
219
220### Gitignore Support
221
222Mccabre respects `.gitignore` files by default:
223
224```bash
225# Respects .gitignore (default)
226mccabre analyze .
227
228# Ignores .gitignore
229mccabre analyze . --no-gitignore
230```
231
232Automatically skips:
233
234- Files/directories in .gitignore
235- `.git/` directory
236- Binary files (by extension)
237
238## Environment Variables
239
240Currently none. Configuration via:
241
2421. CLI flags (highest priority)
2432. Config file
2443. Defaults
245
246## See Also
247
248- [Configuration](./configuration.md)
249- [Cyclomatic Complexity](./cyclomatic-complexity.md)
250- [Clone Detection](./clone-detection.md)
251- [Examples](./examples.md)