Skip to content

ambroslabs/metron

Repository files navigation

metron

A small, dependency-free CLI that counts Rust source lines tokei-style — but with one extra trick: it splits the Code column into Impl and Test so you can see how much of a crate is production code versus tests.

The name is from the Greek μέτρον, "measure."

Install

cargo install ambroslabs-metron

The crate is published as ambroslabs-metron; the installed binary is metron.

Or install the latest from git:

cargo install --git https://github.com/ambroslabs/metron

Or build from a clone:

git clone https://github.com/ambroslabs/metron
cd metron
cargo build --release   # binary at target/release/metron

Usage

metron [--per-file|-f|--ls|-l] [--sort KEY] [--reverse|-r] [PATH]

PATH defaults to the current directory. metron walks every .rs file under it (skipping target/ and dot-directories like .git) and prints a table of line counts.

Aggregation modes

Mode Flag Rows
By subdirectory (default) one row per top-level subdir under PATH; loose files go in a . row
List --ls, -l one row per entry directly under PATH (files individually, subdirs aggregated)
Per file --per-file, -f one row per .rs file, fully recursive

Sorting

--sort KEY where KEY is one of path (default), files, lines, code, impl, test, comments, blanks. Numeric keys default to descending; path defaults to ascending. --reverse / -r flips the chosen key's default direction.

How lines are classified

Each line is one of:

  • blank — only whitespace
  • comment — only // or /* */ comments plus whitespace
  • code — anything else

Strings, char literals, and comments are tracked while scanning so delimiters inside them don't fool the classifier.

Code lines are then split into impl vs test. A line counts as test if it is:

  • inside a #[cfg(test)] item body (brace-balanced), or
  • in a file declared from a parent module via #[cfg(test)] mod NAME;, or
  • under a crate's tests/ or benches/ directory.

Everything else is impl.

License

Licensed under either of Apache-2.0 or MIT at your option.

About

Count Rust source lines, tokei-style, with an impl-vs-test split.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages