Skip to content

Add --max-count to stop after the first N matches - #6

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

Gulliby merged 1 commit into
mainfrom
feature/logslice-max-count

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Requested by gulliby

Adds --max-count N (-m N) to stop after the first N matching records, like grep -m.

Before: logslice printed every match and read the input to its end, even when only the first few records were wanted from a very large log.

After: the tool stops reading as soon as N records have matched (after all filters, across files in argument order). Later files are not opened. --count prints at most N, and --summary summarizes only those N records.

$ logslice errors.log --max-count 2
2026-10-10 12:00:00 ERROR Disk full
2026-10-10 12:00:05 ERROR Timeout

An invalid value (0, 01, -1, abc, 1000000000, empty) is an argument error with exit status 2.

How: parse_max_count validator in src/logslice/filters.py, the option and the early stop in src/logslice/cli.py, README paragraph and options-table row, one new row in the help test, and 34 new cases in tests/test_max_count.py (291 tests in all).

@Gulliby
Gulliby merged commit 46b9466 into main Oct 14, 2026
6 checks passed
@Gulliby
Gulliby deleted the feature/logslice-max-count branch October 14, 2026 19:35
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