Skip to content

Add --count option - #5

Merged
Gulliby merged 1 commit into
mainfrom
feature/logslice-count
Oct 14, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/logslice-count

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Requested by gulliby

Adds a -c / --count option that prints only the number of matching records.

Before. To answer "how many errors in the last hour" a script had to pipe the records to wc -l (not available in Windows PowerShell) or parse the --summary text.

After. --count prints one decimal number and a newline, 0 when nothing matches:

$ logslice errors.log --count
4
$ logslice errors.log --level critical --count
1

It works with --since, --until, --level, --grep, -i and -v, adds up all input files (or standard input), and does not count lines that are not records. --count together with --summary is a usage error (logslice: --count conflicts with --summary, exit status 2), checked after the existing option checks and before the --grep pattern is compiled. When an input file cannot be read, no count is printed.

How. src/logslice/cli.py (new option, conflict check, counter), README.md (paragraph and options table row), tests/test_count.py (20 new test cases) and one additive edit of the help-words test in tests/test_cli.py. No dependency or CI change.

@Gulliby
Gulliby merged commit 04e2596 into main Oct 14, 2026
6 checks passed
@Gulliby
Gulliby deleted the feature/logslice-count branch October 14, 2026 02:40
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.

1 participant