Skip to content

feat: adding range feature for cli#497

Open
Mohiiit wants to merge 7 commits intomainfrom
feat/block-range
Open

feat: adding range feature for cli#497
Mohiiit wants to merge 7 commits intomainfrom
feat/block-range

Conversation

@Mohiiit
Copy link
Copy Markdown
Collaborator

@Mohiiit Mohiiit commented Nov 27, 2025

Add block range support to CLI

Summary

Added --range flag to specify a range of blocks instead of listing each block individually.

Changes

  • Added --range / -R argument accepting start,end format (e.g., --range 1,999)
  • Made --blocks optional (was previously required)
  • Blocks from both --blocks and --range are combined, deduplicated, and sorted
  • Added validation for range format and bounds (start <= end)

Usage

# Range only (blocks 1 to 999 inclusive)
snos --range 1,999 --rpc-url http://...

# Specific blocks only (existing behavior)
snos --blocks 1,5,10 --rpc-url http://...

# Combined
snos --range 1,100 --blocks 150,200 --rpc-url http://...

Environment Variable

The range can also be set via SNOS_RANGE environment variable.

@Mohiiit Mohiiit marked this pull request as ready for review November 27, 2025 10:56
@Mohiiit Mohiiit requested a review from prkpndy as a code owner November 27, 2025 10:56
Copy link
Copy Markdown
Contributor

@glihm glihm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, not blocking for merging, the logic is working fine. 👍

That's quite useful to have this range flag!

Comment thread crates/core/generate-pie/src/main.rs Outdated
.map_err(|_| format!("Invalid end value '{}'. Must be a positive integer.", parts[1]))?;

if start > end {
return Err(format!("Invalid range: start ({}) must be less than or equal to end ({})", start, end));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Err(format!("Invalid range: start ({}) must be less than or equal to end ({})", start, end));
return Err(format!("Invalid range: start ({}) must be less than or equal to end ({}).", start, end));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented on current head: BlockRange::from_str rejects start > end and is covered by test block_range_rejects_start_greater_than_end.

Comment thread crates/core/generate-pie/src/main.rs Outdated
Comment on lines +119 to +132
if let Some(range_str) = &cli.range {
match parse_range(range_str) {
Ok((start, end)) => {
info!("Adding blocks from range {} to {} (inclusive)", start, end);
for block in start..=end {
blocks.insert(block);
}
}
Err(e) => {
error!("Range parsing error: {}", e);
std::process::exit(1);
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic could be simplified letting CLAP managing the deserialization of the arguments by having a BlockRange type + accepting an Option<BlockRange>.

But the current logic works perfectly fine. 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented: CLI now uses Option with Clap deserialization. Added test cli_parses_range_argument_into_block_range.

Comment thread crates/core/generate-pie/src/main.rs Outdated
// Validate that at least one block is provided
if cli.blocks.is_empty() {
error!("At least one block number must be provided");
if blocks.is_empty() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done on the BTreeSet before pending time on converting to vec.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented via collect_blocks: emptiness is validated on BTreeSet before conversion to Vec, with tests for merge/dedupe and empty input.

@Mohiiit Mohiiit requested a review from glihm December 1, 2025 22:17
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