CharMetric is a lightweight and fast CLI tool written in Rust designed to analyze source code files. It provides detailed statistics about line counts, character counts, and blank lines, supporting various output formats, filtering, and exclusion options.
- Recursive Analysis: Scan directories with configurable depth via
walkdir. - Extension Filtering: Focus on specific file types (e.g.,
.rs,.js,.py). - Glob Exclusions: Exclude files or directories with gitignore-style glob patterns.
- Multiple Formats: Standard colored console output and JSON (Normal/Pretty).
- Smart Sorting: Sort results by file format or individual file size.
- Colored Output: Enhanced readability with syntax-highlighted terminal output.
Ensure you have Rust and Cargo installed.
git clone repository
cd Chart-Metric
cargo build --releaseRun the tool using chart-metric [OPTIONS].
chart-metric --path ./srcExclude glob patterns with --exclude (can be used multiple times):
# Exclude a directory by name at any depth
chart-metric --exclude target
# Exclude by glob pattern
chart-metric --exclude "*.lock"
# Multiple exclusions
chart-metric --path . --exclude target --exclude "*.log" --exclude node_modulesPatterns without a / match against the file name at any directory level. Patterns with a / match against the full path.
chart-metric --path ./src --ext rs# Colored table (default)
chart-metric --path ./src
# Pretty JSON
chart-metric --path ./src --format jsPretty
# Compact JSON
chart-metric --path ./src --format jsNormalchart-metric --path ./src --sort file| Option | Description | Default |
|---|---|---|
-p, --path <path> |
Root directory to analyze | . |
--max-iter <n> |
Recursion depth (0 for unlimited) | 0 |
--format <type> |
Output style: normal, jsNormal, jsPretty |
normal |
--sort <type> |
Sort by: fileFormat or file |
fileFormat |
--ext <ext> |
Filter by specific extension | All files |
--exclude <glob> |
Exclude files/dirs matching glob (repeatable) | — |
-h, --help |
Show help message | — |
-V, --version |
Print version | — |
src/
├── main.rs # Entry point wiring all modules
├── cli.rs # CLI argument parsing via clap
├── types.rs # Shared data structures
├── traverse.rs # Directory walking with walkdir + glob exclusions
├── analyze.rs # File reading and line/char/blank counting
├── stats.rs # Statistics aggregation and sorting
└── output.rs # Colored terminal and JSON output formatting
Apache-2.0