Skip to content

Can3299/Char-Metric

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Char Metric

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.

Features

  • 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.

Installation

Ensure you have Rust and Cargo installed.

git clone repository
cd Chart-Metric
cargo build --release

Usage

Run the tool using chart-metric [OPTIONS].

Basic Command

chart-metric --path ./src

Excluding Files or Directories

Exclude 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_modules

Patterns without a / match against the file name at any directory level. Patterns with a / match against the full path.

Extension Filter

chart-metric --path ./src --ext rs

Output Format

# Colored table (default)
chart-metric --path ./src

# Pretty JSON
chart-metric --path ./src --format jsPretty

# Compact JSON
chart-metric --path ./src --format jsNormal

Sort by File (instead of by format group)

chart-metric --path ./src --sort file

Options

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

Project Structure

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

License

Apache-2.0

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages