Skip to content

✨ Support multiple range slices - #196

Draft
ChanTsune wants to merge 2 commits into
mainfrom
feature/multiple-ranges
Draft

✨ Support multiple range slices#196
ChanTsune wants to merge 2 commits into
mainfrom
feature/multiple-ranges

Conversation

@ChanTsune

@ChanTsune ChanTsune commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Support multiple slice ranges as a comma-separated list (e.g., 0:5,10:15)
    • Multi-range slicing works across line, delimiter, and character/byte modes and processes ranges in written order without buffering
  • Documentation

    • README and help updated with multi-range syntax, behavioral notes, and examples
  • Tests

    • Added comprehensive fixtures and tests for multiple ranges, empty ranges, step values, and invalid/overlapping/backward inputs

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7854e903-2c12-400c-8598-4d0da38733db

📥 Commits

Reviewing files that changed from the base of the PR and between 05c1e02 and 767cb81.

📒 Files selected for processing (51)
  • README.md
  • src/cli.rs
  • src/ext/iterator.rs
  • src/main.rs
  • src/range.rs
  • tests/cmd/basic_multiple_ranges.stderr
  • tests/cmd/basic_multiple_ranges.stdin
  • tests/cmd/basic_multiple_ranges.stdout
  • tests/cmd/basic_multiple_ranges.toml
  • tests/cmd/basic_multiple_ranges_backward_rejected.stderr
  • tests/cmd/basic_multiple_ranges_backward_rejected.stdin
  • tests/cmd/basic_multiple_ranges_backward_rejected.stdout
  • tests/cmd/basic_multiple_ranges_backward_rejected.toml
  • tests/cmd/basic_multiple_ranges_empty_middle.stderr
  • tests/cmd/basic_multiple_ranges_empty_middle.stdin
  • tests/cmd/basic_multiple_ranges_empty_middle.stdout
  • tests/cmd/basic_multiple_ranges_empty_middle.toml
  • tests/cmd/basic_multiple_ranges_empty_prefix.stderr
  • tests/cmd/basic_multiple_ranges_empty_prefix.stdin
  • tests/cmd/basic_multiple_ranges_empty_prefix.stdout
  • tests/cmd/basic_multiple_ranges_empty_prefix.toml
  • tests/cmd/basic_multiple_ranges_empty_range.stderr
  • tests/cmd/basic_multiple_ranges_empty_range.stdin
  • tests/cmd/basic_multiple_ranges_empty_range.stdout
  • tests/cmd/basic_multiple_ranges_empty_range.toml
  • tests/cmd/basic_multiple_ranges_overlap_rejected.stderr
  • tests/cmd/basic_multiple_ranges_overlap_rejected.stdin
  • tests/cmd/basic_multiple_ranges_overlap_rejected.stdout
  • tests/cmd/basic_multiple_ranges_overlap_rejected.toml
  • tests/cmd/basic_multiple_ranges_short_input.stderr
  • tests/cmd/basic_multiple_ranges_short_input.stdin
  • tests/cmd/basic_multiple_ranges_short_input.stdout
  • tests/cmd/basic_multiple_ranges_short_input.toml
  • tests/cmd/basic_multiple_ranges_step_boundary.stderr
  • tests/cmd/basic_multiple_ranges_step_boundary.stdin
  • tests/cmd/basic_multiple_ranges_step_boundary.stdout
  • tests/cmd/basic_multiple_ranges_step_boundary.toml
  • tests/cmd/basic_multiple_ranges_step_overlap_rejected.stderr
  • tests/cmd/basic_multiple_ranges_step_overlap_rejected.stdin
  • tests/cmd/basic_multiple_ranges_step_overlap_rejected.stdout
  • tests/cmd/basic_multiple_ranges_step_overlap_rejected.toml
  • tests/cmd/basic_no_args_help.stderr
  • tests/cmd/option_c_multiple_ranges.stderr
  • tests/cmd/option_c_multiple_ranges.stdin
  • tests/cmd/option_c_multiple_ranges.stdout
  • tests/cmd/option_c_multiple_ranges.toml
  • tests/cmd/option_delimiter_multiple_ranges.stderr
  • tests/cmd/option_delimiter_multiple_ranges.stdin
  • tests/cmd/option_delimiter_multiple_ranges.stdout
  • tests/cmd/option_delimiter_multiple_ranges.toml
  • tests/cmd/option_help_long_stdout.stdout
✅ Files skipped from review due to trivial changes (26)
  • tests/cmd/option_c_multiple_ranges.stdin
  • tests/cmd/option_c_multiple_ranges.stdout
  • tests/cmd/basic_multiple_ranges_step_boundary.toml
  • tests/cmd/basic_multiple_ranges_step_overlap_rejected.stdin
  • tests/cmd/basic_multiple_ranges_empty_middle.stdin
  • tests/cmd/basic_multiple_ranges_overlap_rejected.stdin
  • tests/cmd/basic_multiple_ranges_empty_middle.stdout
  • tests/cmd/basic_multiple_ranges_empty_prefix.toml
  • tests/cmd/basic_multiple_ranges_short_input.stdout
  • tests/cmd/basic_multiple_ranges_empty_range.stdout
  • tests/cmd/basic_multiple_ranges_empty_range.toml
  • tests/cmd/basic_multiple_ranges_empty_prefix.stdin
  • tests/cmd/basic_multiple_ranges_step_boundary.stdout
  • tests/cmd/option_delimiter_multiple_ranges.stdin
  • tests/cmd/basic_multiple_ranges_short_input.toml
  • tests/cmd/basic_multiple_ranges_empty_middle.toml
  • tests/cmd/option_c_multiple_ranges.toml
  • tests/cmd/option_delimiter_multiple_ranges.toml
  • tests/cmd/basic_multiple_ranges_backward_rejected.stdin
  • tests/cmd/basic_multiple_ranges.stdout
  • tests/cmd/basic_multiple_ranges_overlap_rejected.stderr
  • tests/cmd/basic_multiple_ranges_backward_rejected.toml
  • tests/cmd/option_help_long_stdout.stdout
  • tests/cmd/basic_multiple_ranges_short_input.stdin
  • tests/cmd/basic_multiple_ranges_backward_rejected.stderr
  • tests/cmd/basic_no_args_help.stderr
🚧 Files skipped from review as they are similar to previous changes (7)
  • tests/cmd/option_delimiter_multiple_ranges.stdout
  • tests/cmd/basic_multiple_ranges.stdin
  • tests/cmd/basic_multiple_ranges.toml
  • tests/cmd/basic_multiple_ranges_overlap_rejected.toml
  • src/range.rs
  • src/cli.rs
  • src/main.rs

📝 Walkthrough

Walkthrough

Adds comma-separated multi-range support to the slice CLI: introduces SliceRanges with validation, a range-aware iterator, new mode helpers that accept &SliceRanges, CLI/help updates, and comprehensive tests and fixtures for multi-range and error cases.

Changes

Multi-Range Slice Support

Layer / File(s) Summary
SliceRanges type definition and validation
src/range.rs
SliceRanges wraps a vector of SliceRange entries parsed from comma-separated input. FromStr implementation validates that ranges are in streaming/non-overlapping order, rejecting backward or overlapping segments and empty comma-delimited parts.
Range-aware iterator for multi-range slicing
src/ext/iterator.rs
Slice<'r, R> iterates a source iterator using a &SliceRanges, tracking an absolute index and active range index, and honors per-range steps. IteratorExt::slice now accepts &SliceRanges; tests updated/added.
Mode helpers and wiring in main
src/main.rs
Adds line_ranges_mode, delimit_ranges_mode, and character_ranges_mode that accept &SliceRanges. Updates multi helper and call sites to pass &SliceRanges, and replaces many tests to use the new mode helpers.
CLI argument type and help text
src/cli.rs
Args.range changes from SliceRange to SliceRanges. Help text documents comma-separated multi-range syntax, streaming-order requirement, rejection of overlapping/backward ranges, and a start:+line experimental note. Tests validate parsing and help text.
Documentation and end-to-end test fixtures
README.md, tests/cmd/*
README and help text updated with multi-range examples (slice 0:5,10:15 file.txt). New and updated command fixtures exercise successful multi-range slicing, empty-range cases, step boundaries, short input behavior, and rejected overlapping/backward ranges with expected stderr/status.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as CLI Parser
  participant Ranges as SliceRanges
  participant Iterator as Slice<'r, R>
  participant Input as Input Source
  participant Output as Output Sink

  User->>CLI: slice 0:2,3:5 file.txt
  CLI->>Ranges: Parse "0:2,3:5"
  Ranges->>Ranges: Validate streaming order
  CLI->>Iterator: slice(&ranges)
  activate Iterator
  loop read elements
    Input->>Iterator: element at index N
    Iterator->>Iterator: Check active range & step
    alt in active range
      Iterator->>Output: Yield element
    else
      Iterator->>Iterator: Skip element
    end
  end
  deactivate Iterator
  Output-->>User: Filtered output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I parsed the commas with nimble paws,
Ranged the lines without a pause,
No rewind, no overlap—just stream,
Multiple slices, like a dream. 🎋

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding support for multiple range slices to the CLI tool, which aligns with the extensive changes across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 92.73% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/multiple-ranges

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChanTsune
ChanTsune force-pushed the feature/multiple-ranges branch from 05c1e02 to c303384 Compare June 5, 2026 01:27
@ChanTsune
ChanTsune force-pushed the feature/multiple-ranges branch from c303384 to f044642 Compare June 5, 2026 01:45
@ChanTsune
ChanTsune marked this pull request as draft June 5, 2026 13:49
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