Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 191 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ categories = ["development-tools", "development-tools::cargo-plugins"]

[dependencies]
clap = { version = "4.5", features = ["derive"] }
csv = "1.4.0"
ignore = "0.4.23"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
serde_yaml_bw = "2.5.5"
utf8-chars = "3.0.5"
walkdir = "2.5.0"
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ about our project documentation being bigger than the code itself.
* Understands (to a limit) Rust syntax, so is more accurate in its counts then most generic LOC counters.
* Does not count ignored (by `.gitignore`) files.
* Can optionally give you stats file-by-file.
* Output stats in tables, CSV, JSON, or YAML.

Here is the output for the `cargo` repository:

Here is the output for `cargo` repository:
```
File count: 1188
Type | Code | Blank | Doc comments | Comments | Total
Type | Code | Blank | Doc comments | Comments | Total
-------------|--------------|--------------|--------------|--------------|-------------
Main | 82530 | 9682 | 12625 | 6220 | 111057
Tests | 144421 | 20538 | 588 | 10151 | 175698
Examples | 169 | 27 | 5 | 19 | 220
Main | 82530 | 9682 | 12625 | 6220 | 111057
Tests | 144421 | 20538 | 588 | 10151 | 175698
Examples | 169 | 27 | 5 | 19 | 220
-------------|--------------|--------------|--------------|--------------|-------------
| 227120 | 30247 | 13218 | 16390 | 286975
| 227120 | 30247 | 13218 | 16390 | 286975
```

# Installation
Expand All @@ -34,7 +36,7 @@ cargo install cargo-warloc
# Usage

```shell
cargo warloc
cargo warloc [--by-file] [-o tabular|csv|json|yaml]
```

# Contributing
Expand Down
29 changes: 28 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use clap::Parser;
use std::fmt::Display;

use clap::{Parser, ValueEnum};

/// Wise analysis of Rust lines of code
///
Expand All @@ -14,6 +16,31 @@ pub struct Cli {
/// If set, will print out stats for each file separately
#[arg(long)]
pub by_file: bool,
/// Output format to print to standard output
#[arg(short, long, default_value_t = OutputFormat::Tabular)]
pub output_format: OutputFormat,
}

#[derive(Clone, Debug, Default, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "lower")]
pub enum OutputFormat {
#[default]
Tabular,
Json,
Csv,
Yaml,
}

impl Display for OutputFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Tabular => "tabular",
Self::Yaml => "yaml",
Self::Csv => "csv",
Self::Json => "json",
};
f.write_str(s)
}
}

#[derive(Parser)]
Expand Down
Loading
Loading