Conversation
glihm
left a comment
There was a problem hiding this comment.
Minor comments, not blocking for merging, the logic is working fine. 👍
That's quite useful to have this range flag!
| .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)); |
There was a problem hiding this comment.
| 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)); |
There was a problem hiding this comment.
Implemented on current head: BlockRange::from_str rejects start > end and is covered by test block_range_rejects_start_greater_than_end.
| 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); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
Implemented: CLI now uses Option with Clap deserialization. Added test cli_parses_range_argument_into_block_range.
| // 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() { |
There was a problem hiding this comment.
Could be done on the BTreeSet before pending time on converting to vec.
There was a problem hiding this comment.
Implemented via collect_blocks: emptiness is validated on BTreeSet before conversion to Vec, with tests for merge/dedupe and empty input.
Add block range support to CLI
Summary
Added
--rangeflag to specify a range of blocks instead of listing each block individually.Changes
--range/-Rargument acceptingstart,endformat (e.g.,--range 1,999)--blocksoptional (was previously required)--blocksand--rangeare combined, deduplicated, and sortedstart <= end)Usage
Environment Variable
The range can also be set via
SNOS_RANGEenvironment variable.