mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:34 +00:00
Allow units for --block-size
This commit is contained in:
1 parent
c3dd4e871e
commit
1b1fc4b053
1 file changed
+7
-3
+7
-3
@@ -147,9 +147,13 @@ fn run() -> Result<(), AnyhowError> {
|
||||
let block_size = matches
|
||||
.value_of("block_size")
|
||||
.map(|bs| {
|
||||
bs.parse::<i64>().map_err(|e| anyhow!(e)).and_then(|x| {
|
||||
PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
|
||||
})
|
||||
let (num, unit) = extract_num_and_unit_from(bs)?;
|
||||
num.checked_mul(unit.get_multiplier())
|
||||
.ok_or_else(|| anyhow!(ByteOffsetParseError::UnitMultiplicationOverflow))
|
||||
.and_then(|x| {
|
||||
PositiveI64::new(x)
|
||||
.ok_or_else(|| anyhow!("block size argument must be positive"))
|
||||
})
|
||||
})
|
||||
.transpose()?
|
||||
.unwrap_or_else(|| PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap());
|
||||
|
||||
Reference in new issue
Block a user