Skip to content

Commit b7d0704

Browse files
committed
fix: CLI argument parsing error
1 parent e956cc4 commit b7d0704

2 files changed

Lines changed: 10 additions & 23 deletions

File tree

crates/pithos/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ enum ReadCommands {
136136
#[arg(value_name = "PATH")]
137137
path: PathBuf,
138138
/// Specific byte ranges in the file
139-
#[arg(short, long, value_parser=parse_range_input, value_name = "START:END,...")]
139+
#[arg(short, long, value_parser=parse_range_input, value_delimiter=',', value_name = "START:END,...")]
140140
ranges: Option<Vec<Range<u64>>>,
141141
},
142142
/// Read the Table of Contents

crates/pithos/src/utils/conversion.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,14 @@ pub fn _to_hex_string(bytes: Vec<u8>) -> String {
2222
hex_str.join("")
2323
}
2424

25-
pub fn parse_range_input(input: &str) -> Result<Vec<Range<u64>>, PithosCliError> {
26-
if input.is_empty() {
27-
return Err(PithosCliError::InvalidArgumentError(
28-
"Provided empty ranges argument".to_string(),
29-
));
30-
}
31-
32-
let ranges: Vec<&str> = input.split(',').collect();
33-
let mut parsed_ranges = Vec::new();
34-
for range in ranges {
35-
let parts: Vec<&str> = range.split(':').collect();
36-
37-
let start = parts[0].trim().parse::<u64>().map_err(|e| {
38-
PithosCliError::InvalidArgumentError(format!("Failed to parse range start: {}", e))
39-
})?;
40-
let end = parts[1].trim().parse::<u64>().map_err(|e| {
41-
PithosCliError::InvalidArgumentError(format!("Failed to parse range end: {}", e))
42-
})?;
43-
44-
parsed_ranges.push(start..end)
45-
}
25+
pub fn parse_range_input(input: &str) -> Result<Range<u64>, PithosCliError> {
26+
let parts: Vec<&str> = input.split(':').collect();
27+
let start = parts[0].trim().parse::<u64>().map_err(|e| {
28+
PithosCliError::InvalidArgumentError(format!("Failed to parse range start: {}", e))
29+
})?;
30+
let end = parts[1].trim().parse::<u64>().map_err(|e| {
31+
PithosCliError::InvalidArgumentError(format!("Failed to parse range end: {}", e))
32+
})?;
4633

47-
Ok(parsed_ranges)
34+
Ok(start..end)
4835
}

0 commit comments

Comments
 (0)