mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
add ability to parse strings like "100kib" and "100 kib"
This commit is contained in:
parent
1ea124a65b
commit
ffd922f393
3 changed files with 10 additions and 2 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -113,6 +113,12 @@ dependencies = [
|
|||
"utf8-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytesize"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.71"
|
||||
|
@ -533,6 +539,7 @@ dependencies = [
|
|||
name = "nu-command"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytesize",
|
||||
"chrono",
|
||||
"glob",
|
||||
"lscolors",
|
||||
|
|
|
@ -22,6 +22,7 @@ sysinfo = "0.20.4"
|
|||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
terminal_size = "0.1.17"
|
||||
lscolors = { version = "0.8.0", features = ["crossterm"] }
|
||||
bytesize = "1.1.0"
|
||||
|
||||
[features]
|
||||
trash-support = ["trash"]
|
||||
|
|
|
@ -160,8 +160,8 @@ pub fn action(input: Value, span: Span) -> Value {
|
|||
}
|
||||
}
|
||||
fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
match a_string.parse::<i64>() {
|
||||
Ok(n) => Ok(n),
|
||||
match a_string.parse::<bytesize::ByteSize>() {
|
||||
Ok(n) => Ok(n.0 as i64),
|
||||
Err(_) => Err(ShellError::CantConvert("int".into(), span)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue