From ffd922f393f8da4c273d66082a25613f93fb0a93 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 12 Oct 2021 15:22:12 -0500 Subject: [PATCH] add ability to parse strings like "100kib" and "100 kib" --- Cargo.lock | 7 +++++++ crates/nu-command/Cargo.toml | 1 + crates/nu-command/src/conversions/into/filesize.rs | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21a24b46e1..03b6548148 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 1eed40b672..90f623468a 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -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"] diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index 207a22481a..1e1b730071 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -160,8 +160,8 @@ pub fn action(input: Value, span: Span) -> Value { } } fn int_from_string(a_string: &str, span: Span) -> Result { - match a_string.parse::() { - Ok(n) => Ok(n), + match a_string.parse::() { + Ok(n) => Ok(n.0 as i64), Err(_) => Err(ShellError::CantConvert("int".into(), span)), } }