code complexity & repetition analysis tool
mccabre docs src cli-reference.md
6.6 kB · 340 lines
Markdown
at main

CLI Reference #

Commands #

analyze #

Run full analysis (complexity + clones + LOC).

mccabre analyze [OPTIONS] [PATH]

Arguments:

  • [PATH] - Path to file or directory (default: .)

Options:

  • -j, --json - Output in JSON format
  • --threshold <N> - Complexity warning threshold
  • --min-tokens <N> - Minimum tokens for clone detection (default: 30)
  • -c, --config <FILE> - Path to config file
  • --no-gitignore - Disable gitignore awareness
  • --no-highlight - Disable syntax highlighting for code blocks

Examples:

# Analyze current directory
mccabre analyze

# Analyze specific path with JSON output
mccabre analyze ./src --json

# Custom thresholds
mccabre analyze ./src --threshold 15 --min-tokens 25

complexity #

Analyze cyclomatic complexity and LOC only.

mccabre complexity [OPTIONS] [PATH]

Arguments:

  • [PATH] - Path to file or directory (default: .)

Options:

  • -j, --json - Output in JSON format
  • --threshold <N> - Complexity warning threshold
  • -c, --config <FILE> - Path to config file
  • --no-gitignore - Disable gitignore awareness

Examples:

# Check complexity of src/
mccabre complexity src/

# Fail if any file exceeds complexity of 20
mccabre complexity src/ --threshold 20

clones #

Detect code clones only.

mccabre clones [OPTIONS] [PATH]

Arguments:

  • [PATH] - Path to file or directory (default: .)

Options:

  • -j, --json - Output in JSON format
  • --min-tokens <N> - Minimum tokens for detection (default: 30)
  • -c, --config <FILE> - Path to config file
  • --no-gitignore - Disable gitignore awareness
  • --no-highlight - Disable syntax highlighting for code blocks

Examples:

# Find clones in current directory
mccabre clones .

# Find only large clones (50+ tokens)
mccabre clones . --min-tokens 50

# JSON output for processing
mccabre clones src/ --json | jq '.clones | length'

dump-config #

Display and optionally save current configuration.

mccabre dump-config [OPTIONS]

Options:

  • -c, --config <FILE> - Path to config file (shows default if not specified)
  • -o, --output <PATH> - Save configuration to file or directory

Examples:

# Show default configuration
mccabre dump-config

# Show loaded configuration
mccabre dump-config --config mccabre.toml

# Save default config to file
mccabre dump-config -o my-config.toml

# Save config to directory (creates mccabre.toml)
mccabre dump-config -o ./configs/

# Load and save to new location
mccabre dump-config -c old-config.toml -o new-config.toml

loc #

Analyze lines of code with file or directory ranking.

mccabre loc [OPTIONS] [PATH]

Arguments:

  • [PATH] - Path to file or directory (default: .)

Options:

  • -j, --json - Output in JSON format
  • --rank-by <METRIC> - Rank by logical, physical, comments, or blank (default: logical)
  • --rank-dirs - Rank directories, with files ranked within each directory
  • -c, --config <FILE> - Path to config file
  • --no-gitignore - Disable gitignore awareness

Examples:

# Rank files by logical LOC
mccabre loc src/

# Rank files by comment lines
mccabre loc src/ --rank-by comments

# Rank directories by physical LOC
mccabre loc src/ --rank-dirs --rank-by physical

coverage report #

Show an LCOV coverage summary and optionally write JSONL or HTML output.

mccabre coverage report --from <PATH> [OPTIONS]

Options:

  • --from <PATH> - Path to LCOV file
  • --jsonl <PATH> - Write one JSON object per file to a JSONL file
  • --html <DIR> - Write a static HTML report to a directory
  • --repo-root <PATH> - Repository root for path normalization

Examples:

# Print a terminal coverage report
mccabre coverage report --from lcov.info

# Also write JSONL and HTML artifacts
mccabre coverage report --from lcov.info --jsonl coverage.jsonl --html coverage-html/

coverage show #

Show detailed coverage for all files, one directory, or one file.

mccabre coverage show --from <PATH> [OPTIONS] [PATH]

Arguments:

  • [PATH] - Optional source file or directory to show

Options:

  • --from <PATH> - Path to LCOV file
  • --repo-root <PATH> - Repository root for path normalization
  • --truncate-threshold <N> - Minimum consecutive ignored lines before truncation (default: 5)

Examples:

# List all files from the LCOV data
mccabre coverage show --from lcov.info

# Show a directory summary
mccabre coverage show --from lcov.info src/

# Show annotated source for one file
mccabre coverage show --from lcov.info src/lib.rs

Global Options #

-h, --help #

Show help information.

mccabre --help
mccabre analyze --help

-V, --version #

Show version information.

mccabre --version

Output Formats #

Terminal (Default) #

Colored, human-readable output:

FILE: src/main.rs
    Cyclomatic Complexity:   15 (warning)
    Physical LOC:            120
    Logical LOC:             85

Colors:

  • Green: Low/good
  • Yellow: Moderate/warning
  • Red: High/error

JSON #

Machine-readable output for CI/CD:

mccabre analyze src/ --json
{
  "files": [
    {
      "path": "src/main.rs",
      "loc": {
        "physical": 120,
        "logical": 85,
        "comments": 25,
        "blank": 10
      },
      "cyclomatic": {
        "file_complexity": 15,
        "functions": []
      }
    }
  ],
  "clones": [],
  "summary": {
    "total_files": 1,
    "total_physical_loc": 120,
    "total_logical_loc": 85,
    "avg_complexity": 15.0,
    "max_complexity": 15,
    "high_complexity_files": 1,
    "total_clones": 0
  }
}

File Selection #

Supported Languages #

  • Rust: .rs
  • JavaScript: .js, .jsx, .mjs, .cjs
  • TypeScript: .ts, .tsx
  • Go: .go
  • Java: .java
  • C++: .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx

Gitignore Support #

Mccabre respects .gitignore files by default:

# Respects .gitignore (default)
mccabre analyze .

# Ignores .gitignore
mccabre analyze . --no-gitignore

Automatically skips:

  • Files/directories in .gitignore
  • .git/ directory
  • Files with unsupported extensions

Environment Variables #

Currently none. Configuration via:

  1. CLI flags (highest priority)
  2. Config file
  3. Defaults

See Also #