Skip to content

Add --total option to append a Total column to reports - #984

Merged
AlDanial merged 1 commit into
AlDanial:masterfrom
pascal-lc:add-total-option
Sep 20, 2026
Merged

AlDanial merged 1 commit into
AlDanial:masterfrom
pascal-lc:add-total-option

Conversation

@pascal-lc

Copy link
Copy Markdown

The standard report shows only blank, comment, and code counts per
language; there is no per-language total of all three. Add a --total
option that appends a Total column (blank + comment + code) to every
language/file row and to the SUM row.

  • Applies to the text, Markdown, CSV, XML, YAML, and JSON reports.
  • Works with --by-file, --by-file-by-lang, --by-percent (the Total
    column shows the raw line count), --3, and --sum-reports.
  • combine_results tolerates the extra column, so --sum-reports works
    with reports generated with --total while remaining backward
    compatible with reports without the column.
  • Ignored with --diff and --sql (documented in --help).
  • Regression tests added in Unix/t/01_opts.t; full suite passes
    (678 language tests + 285 option tests).

The standard report only shows per-language blank, comment, and code
counts.  Add a --total option that appends a Total column (blank +
comment + code) to each language/file row and to the SUM row, across
the text, Markdown, CSV, XML, YAML, and JSON reports.

combine_results tolerates the extra column so --sum-reports still
works with reports generated with --total, while remaining backward
compatible with reports without it.

Regression tests added in Unix/t/01_opts.t.
@AlDanial

Copy link
Copy Markdown
Owner

It will be ~ 2 weeks before I can look at this.

@AlDanial

Copy link
Copy Markdown
Owner

I tested your code but am wondering what --total does that isn't already implemented with --fmt 2, --fmt 4, and --fmt 5. I will grant you that --total is easier to understand.

@pascal-lc

Copy link
Copy Markdown
Author

I developed this against the cloc 1.96 package in Debian bookworm, which predates --fmt (v2.00, Feb 2024), so I missed that this already existed upstream -- my apologies for the overlap.

That said, --total also applies to the Markdown, CSV, XML, YAML, and JSON reports (--fmt is text-only) and is easier to use. If that's worth having, I'm happy to rework it; otherwise feel free to close this PR as a duplicate.

@AlDanial

Copy link
Copy Markdown
Owner

Good point on covering the formatted outputs. I need to figure out a clean way to merge your work in.

@AlDanial
AlDanial merged commit 2b7f7d2 into AlDanial:master Sep 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants