mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-30 09:05:54 +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
|
let block_size = matches
|
||||||
.value_of("block_size")
|
.value_of("block_size")
|
||||||
.map(|bs| {
|
.map(|bs| {
|
||||||
bs.parse::<i64>().map_err(|e| anyhow!(e)).and_then(|x| {
|
let (num, unit) = extract_num_and_unit_from(bs)?;
|
||||||
PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
|
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()?
|
.transpose()?
|
||||||
.unwrap_or_else(|| PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap());
|
.unwrap_or_else(|| PositiveI64::new(DEFAULT_BLOCK_SIZE).unwrap());
|
||||||
|
|||||||
Reference in new issue
Block a user