diff --git a/crates/nu-cli/src/commands/du.rs b/crates/nu-cli/src/commands/du.rs index 32a041dd5..582703284 100644 --- a/crates/nu-cli/src/commands/du.rs +++ b/crates/nu-cli/src/commands/du.rs @@ -357,12 +357,12 @@ impl From for Value { r.insert( "apparent".to_string(), - UntaggedValue::bytes(d.size).into_value(&d.tag), + UntaggedValue::filesize(d.size).into_value(&d.tag), ); r.insert( "physical".to_string(), - UntaggedValue::bytes(d.blocks).into_value(&d.tag), + UntaggedValue::filesize(d.blocks).into_value(&d.tag), ); r.insert("directories".to_string(), value_from_vec(d.dirs, &d.tag)); @@ -399,12 +399,12 @@ impl From for Value { r.insert( "apparent".to_string(), - UntaggedValue::bytes(f.size).into_value(&f.tag), + UntaggedValue::filesize(f.size).into_value(&f.tag), ); let b = f .blocks - .map(UntaggedValue::bytes) + .map(UntaggedValue::filesize) .unwrap_or_else(UntaggedValue::nothing) .into_value(&f.tag); diff --git a/crates/nu-cli/src/commands/math/avg.rs b/crates/nu-cli/src/commands/math/avg.rs index bb96490e1..71729c3cb 100644 --- a/crates/nu-cli/src/commands/math/avg.rs +++ b/crates/nu-cli/src/commands/math/avg.rs @@ -71,7 +71,7 @@ pub fn average(values: &[Value], name: &Tag) -> Result { match total { Value { - value: UntaggedValue::Primitive(Primitive::Bytes(num)), + value: UntaggedValue::Primitive(Primitive::Filesize(num)), .. } => { let left = UntaggedValue::from(Primitive::Int(num.into())); @@ -81,7 +81,7 @@ pub fn average(values: &[Value], name: &Tag) -> Result { Ok(UntaggedValue::Primitive(Primitive::Decimal(result))) => { let number = Number::Decimal(result); let number = convert_number_to_u64(&number); - Ok(UntaggedValue::bytes(number).into_value(name)) + Ok(UntaggedValue::filesize(number).into_value(name)) } Ok(_) => Err(ShellError::labeled_error( "could not calculate average of non-integer or unrelated types", diff --git a/crates/nu-cli/src/commands/math/median.rs b/crates/nu-cli/src/commands/math/median.rs index e376e97b5..36f223ba1 100644 --- a/crates/nu-cli/src/commands/math/median.rs +++ b/crates/nu-cli/src/commands/math/median.rs @@ -134,7 +134,7 @@ fn compute_average(values: &[Value], name: impl Into) -> Result { let left = UntaggedValue::from(Primitive::Int(num.into())); @@ -144,7 +144,7 @@ fn compute_average(values: &[Value], name: impl Into) -> Result { let number = Number::Decimal(result); let number = convert_number_to_u64(&number); - Ok(UntaggedValue::bytes(number).into_value(name)) + Ok(UntaggedValue::filesize(number).into_value(name)) } Ok(_) => Err(ShellError::labeled_error( "could not calculate median of non-numeric or unrelated types", diff --git a/crates/nu-cli/src/commands/to_bson.rs b/crates/nu-cli/src/commands/to_bson.rs index c4241d8b4..f06110379 100644 --- a/crates/nu-cli/src/commands/to_bson.rs +++ b/crates/nu-cli/src/commands/to_bson.rs @@ -41,7 +41,7 @@ pub fn value_to_bson_value(v: &Value) -> Result { Ok(match &v.value { UntaggedValue::Primitive(Primitive::Boolean(b)) => Bson::Boolean(*b), // FIXME: What about really big decimals? - UntaggedValue::Primitive(Primitive::Bytes(decimal)) => Bson::FloatingPoint( + UntaggedValue::Primitive(Primitive::Filesize(decimal)) => Bson::FloatingPoint( (decimal) .to_f64() .expect("Unimplemented BUG: What about big decimals?"), diff --git a/crates/nu-cli/src/commands/to_delimited_data.rs b/crates/nu-cli/src/commands/to_delimited_data.rs index 010becdcb..01562b279 100644 --- a/crates/nu-cli/src/commands/to_delimited_data.rs +++ b/crates/nu-cli/src/commands/to_delimited_data.rs @@ -115,8 +115,8 @@ pub fn clone_tagged_value(v: &Value) -> Value { UntaggedValue::Primitive(Primitive::Path(x)) => { UntaggedValue::Primitive(Primitive::Path(x.clone())) } - UntaggedValue::Primitive(Primitive::Bytes(b)) => { - UntaggedValue::Primitive(Primitive::Bytes(*b)) + UntaggedValue::Primitive(Primitive::Filesize(b)) => { + UntaggedValue::Primitive(Primitive::Filesize(*b)) } UntaggedValue::Primitive(Primitive::Date(d)) => { UntaggedValue::Primitive(Primitive::Date(*d)) @@ -134,7 +134,7 @@ fn to_string_tagged_value(v: &Value) -> Result { match &v.value { UntaggedValue::Primitive(Primitive::String(_)) | UntaggedValue::Primitive(Primitive::Line(_)) - | UntaggedValue::Primitive(Primitive::Bytes(_)) + | UntaggedValue::Primitive(Primitive::Filesize(_)) | UntaggedValue::Primitive(Primitive::Boolean(_)) | UntaggedValue::Primitive(Primitive::Decimal(_)) | UntaggedValue::Primitive(Primitive::Path(_)) diff --git a/crates/nu-cli/src/commands/to_json.rs b/crates/nu-cli/src/commands/to_json.rs index 9a3a98206..be2373ab4 100644 --- a/crates/nu-cli/src/commands/to_json.rs +++ b/crates/nu-cli/src/commands/to_json.rs @@ -62,7 +62,7 @@ impl WholeStreamCommand for ToJSON { pub fn value_to_json_value(v: &Value) -> Result { Ok(match &v.value { UntaggedValue::Primitive(Primitive::Boolean(b)) => serde_json::Value::Bool(*b), - UntaggedValue::Primitive(Primitive::Bytes(b)) => serde_json::Value::Number( + UntaggedValue::Primitive(Primitive::Filesize(b)) => serde_json::Value::Number( serde_json::Number::from(b.to_u64().expect("What about really big numbers")), ), UntaggedValue::Primitive(Primitive::Duration(i)) => { diff --git a/crates/nu-cli/src/commands/to_sqlite.rs b/crates/nu-cli/src/commands/to_sqlite.rs index 0fbbede2a..1e30edf90 100644 --- a/crates/nu-cli/src/commands/to_sqlite.rs +++ b/crates/nu-cli/src/commands/to_sqlite.rs @@ -93,7 +93,7 @@ fn nu_value_to_sqlite_string(v: Value) -> String { Primitive::Int(i) => format!("{}", i), Primitive::Duration(i) => format!("{}", i), Primitive::Decimal(f) => format!("{}", f), - Primitive::Bytes(u) => format!("{}", u), + Primitive::Filesize(u) => format!("{}", u), Primitive::Pattern(s) => format!("'{}'", s.replace("'", "''")), Primitive::String(s) => format!("'{}'", s.replace("'", "''")), Primitive::Line(s) => format!("'{}'", s.replace("'", "''")), diff --git a/crates/nu-cli/src/commands/to_toml.rs b/crates/nu-cli/src/commands/to_toml.rs index 77880e6c2..bbd012d47 100644 --- a/crates/nu-cli/src/commands/to_toml.rs +++ b/crates/nu-cli/src/commands/to_toml.rs @@ -44,7 +44,7 @@ impl WholeStreamCommand for ToTOML { fn helper(v: &Value) -> Result { Ok(match &v.value { UntaggedValue::Primitive(Primitive::Boolean(b)) => toml::Value::Boolean(*b), - UntaggedValue::Primitive(Primitive::Bytes(b)) => toml::Value::Integer(*b as i64), + UntaggedValue::Primitive(Primitive::Filesize(b)) => toml::Value::Integer(*b as i64), UntaggedValue::Primitive(Primitive::Duration(i)) => toml::Value::String(i.to_string()), UntaggedValue::Primitive(Primitive::Date(d)) => toml::Value::String(d.to_string()), UntaggedValue::Primitive(Primitive::EndOfStream) => { diff --git a/crates/nu-cli/src/commands/to_yaml.rs b/crates/nu-cli/src/commands/to_yaml.rs index 4baa885df..8cc5c6419 100644 --- a/crates/nu-cli/src/commands/to_yaml.rs +++ b/crates/nu-cli/src/commands/to_yaml.rs @@ -31,7 +31,7 @@ impl WholeStreamCommand for ToYAML { pub fn value_to_yaml_value(v: &Value) -> Result { Ok(match &v.value { UntaggedValue::Primitive(Primitive::Boolean(b)) => serde_yaml::Value::Bool(*b), - UntaggedValue::Primitive(Primitive::Bytes(b)) => { + UntaggedValue::Primitive(Primitive::Filesize(b)) => { serde_yaml::Value::Number(serde_yaml::Number::from(b.to_f64().ok_or_else(|| { ShellError::labeled_error( "Could not convert to bytes", diff --git a/crates/nu-cli/src/commands/trim.rs b/crates/nu-cli/src/commands/trim.rs index 309b951b8..a324eb909 100644 --- a/crates/nu-cli/src/commands/trim.rs +++ b/crates/nu-cli/src/commands/trim.rs @@ -43,7 +43,7 @@ fn trim_primitive(p: &mut Primitive) { Primitive::Nothing | Primitive::Int(_) | Primitive::Decimal(_) - | Primitive::Bytes(_) + | Primitive::Filesize(_) | Primitive::ColumnPath(_) | Primitive::Pattern(_) | Primitive::Boolean(_) diff --git a/crates/nu-cli/src/data/base.rs b/crates/nu-cli/src/data/base.rs index 8b6f49083..8bef57d6c 100644 --- a/crates/nu-cli/src/data/base.rs +++ b/crates/nu-cli/src/data/base.rs @@ -138,19 +138,19 @@ fn coerce_compare_primitive( (Int(left), Decimal(right)) => { CompareValues::Decimals(BigDecimal::zero() + left, right.clone()) } - (Int(left), Bytes(right)) => CompareValues::Ints(left.clone(), BigInt::from(*right)), + (Int(left), Filesize(right)) => CompareValues::Ints(left.clone(), BigInt::from(*right)), (Decimal(left), Decimal(right)) => CompareValues::Decimals(left.clone(), right.clone()), (Decimal(left), Int(right)) => { CompareValues::Decimals(left.clone(), BigDecimal::zero() + right) } - (Decimal(left), Bytes(right)) => { + (Decimal(left), Filesize(right)) => { CompareValues::Decimals(left.clone(), BigDecimal::from(*right)) } - (Bytes(left), Bytes(right)) => { + (Filesize(left), Filesize(right)) => { CompareValues::Ints(BigInt::from(*left), BigInt::from(*right)) } - (Bytes(left), Int(right)) => CompareValues::Ints(BigInt::from(*left), right.clone()), - (Bytes(left), Decimal(right)) => { + (Filesize(left), Int(right)) => CompareValues::Ints(BigInt::from(*left), right.clone()), + (Filesize(left), Decimal(right)) => { CompareValues::Decimals(BigDecimal::from(*left), right.clone()) } (Nothing, Nothing) => CompareValues::Booleans(true, true), diff --git a/crates/nu-cli/src/data/base/shape.rs b/crates/nu-cli/src/data/base/shape.rs index d98680ba9..621ae1d67 100644 --- a/crates/nu-cli/src/data/base/shape.rs +++ b/crates/nu-cli/src/data/base/shape.rs @@ -64,7 +64,7 @@ impl InlineShape { })) } Primitive::Decimal(decimal) => InlineShape::Decimal(decimal.clone()), - Primitive::Bytes(bytesize) => InlineShape::Bytesize(*bytesize), + Primitive::Filesize(bytesize) => InlineShape::Bytesize(*bytesize), Primitive::String(string) => InlineShape::String(string.clone()), Primitive::Line(string) => InlineShape::Line(string.clone()), Primitive::ColumnPath(path) => InlineShape::ColumnPath(path.clone()), diff --git a/crates/nu-cli/src/data/files.rs b/crates/nu-cli/src/data/files.rs index 1824d7c3c..e8ff6f959 100644 --- a/crates/nu-cli/src/data/files.rs +++ b/crates/nu-cli/src/data/files.rs @@ -168,12 +168,12 @@ pub(crate) fn dir_entry_dict( md.len() }; - size_untagged_value = UntaggedValue::bytes(dir_size); + size_untagged_value = UntaggedValue::filesize(dir_size); } else if md.is_file() { - size_untagged_value = UntaggedValue::bytes(md.len()); + size_untagged_value = UntaggedValue::filesize(md.len()); } else if md.file_type().is_symlink() { if let Ok(symlink_md) = filename.symlink_metadata() { - size_untagged_value = UntaggedValue::bytes(symlink_md.len() as u64); + size_untagged_value = UntaggedValue::filesize(symlink_md.len() as u64); } } diff --git a/crates/nu-cli/src/data/primitive.rs b/crates/nu-cli/src/data/primitive.rs index 666bd95fd..d9cabc981 100644 --- a/crates/nu-cli/src/data/primitive.rs +++ b/crates/nu-cli/src/data/primitive.rs @@ -12,7 +12,9 @@ pub fn number(number: impl Into) -> Primitive { pub fn style_primitive(primitive: &Primitive) -> TextStyle { match primitive { - Primitive::Int(_) | Primitive::Bytes(_) | Primitive::Decimal(_) => TextStyle::basic_right(), + Primitive::Int(_) | Primitive::Filesize(_) | Primitive::Decimal(_) => { + TextStyle::basic_right() + } _ => TextStyle::basic(), } } diff --git a/crates/nu-cli/src/data/value.rs b/crates/nu-cli/src/data/value.rs index 1dd9a90b4..fd6e3f262 100644 --- a/crates/nu-cli/src/data/value.rs +++ b/crates/nu-cli/src/data/value.rs @@ -47,13 +47,13 @@ pub fn compute_values( ) -> Result { match (left, right) { (UntaggedValue::Primitive(lhs), UntaggedValue::Primitive(rhs)) => match (lhs, rhs) { - (Primitive::Bytes(x), Primitive::Bytes(y)) => { + (Primitive::Filesize(x), Primitive::Filesize(y)) => { let result = match operator { Operator::Plus => Ok(x + y), Operator::Minus => Ok(x - y), _ => Err((left.type_name(), right.type_name())), }?; - Ok(UntaggedValue::Primitive(Primitive::Bytes(result))) + Ok(UntaggedValue::Primitive(Primitive::Filesize(result))) } (Primitive::Int(x), Primitive::Int(y)) => match operator { Operator::Plus => Ok(UntaggedValue::Primitive(Primitive::Int(x + y))), diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 4988891b9..c5df1d6e3 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -497,13 +497,13 @@ impl Unit { let size = size.clone(); match self { - Unit::Byte => bytes(convert_number_to_u64(&size)), - Unit::Kilobyte => bytes(convert_number_to_u64(&size) * 1024), - Unit::Megabyte => bytes(convert_number_to_u64(&size) * 1024 * 1024), - Unit::Gigabyte => bytes(convert_number_to_u64(&size) * 1024 * 1024 * 1024), - Unit::Terabyte => bytes(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024), + Unit::Byte => filesize(convert_number_to_u64(&size)), + Unit::Kilobyte => filesize(convert_number_to_u64(&size) * 1024), + Unit::Megabyte => filesize(convert_number_to_u64(&size) * 1024 * 1024), + Unit::Gigabyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024), + Unit::Terabyte => filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024), Unit::Petabyte => { - bytes(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024 * 1024) + filesize(convert_number_to_u64(&size) * 1024 * 1024 * 1024 * 1024 * 1024) } Unit::Nanosecond => duration(size.to_bigint().expect("Conversion should never fail.")), Unit::Microsecond => { @@ -571,8 +571,8 @@ impl Unit { } } -pub fn bytes(size: u64) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Bytes(size)) +pub fn filesize(size_in_bytes: u64) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Filesize(size_in_bytes)) } pub fn duration(nanos: BigInt) -> UntaggedValue { diff --git a/crates/nu-protocol/src/type_shape.rs b/crates/nu-protocol/src/type_shape.rs index c3897fa93..9810908ea 100644 --- a/crates/nu-protocol/src/type_shape.rs +++ b/crates/nu-protocol/src/type_shape.rs @@ -34,7 +34,7 @@ pub enum Type { /// A decimal (floating point) value Decimal, /// A filesize in bytes - Bytesize, + Filesize, /// A string of text String, /// A line of text (a string with trailing line ending) @@ -138,7 +138,7 @@ impl Type { Type::Range(Box::new(range)) } Primitive::Decimal(_) => Type::Decimal, - Primitive::Bytes(_) => Type::Bytesize, + Primitive::Filesize(_) => Type::Filesize, Primitive::String(_) => Type::String, Primitive::Line(_) => Type::Line, Primitive::ColumnPath(_) => Type::ColumnPath, @@ -220,7 +220,7 @@ impl PrettyDebug for Type { ) } Type::Decimal => ty("decimal"), - Type::Bytesize => ty("bytesize"), + Type::Filesize => ty("filesize"), Type::String => ty("string"), Type::Line => ty("line"), Type::ColumnPath => ty("column-path"), diff --git a/crates/nu-protocol/src/value.rs b/crates/nu-protocol/src/value.rs index 5335acc62..8ceaa2b86 100644 --- a/crates/nu-protocol/src/value.rs +++ b/crates/nu-protocol/src/value.rs @@ -183,9 +183,9 @@ impl UntaggedValue { UntaggedValue::Primitive(Primitive::Path(s.into())) } - /// Helper for creating bytesize values - pub fn bytes(s: impl Into) -> UntaggedValue { - UntaggedValue::Primitive(Primitive::Bytes(s.into())) + /// Helper for creating filesize values + pub fn filesize(s: impl Into) -> UntaggedValue { + UntaggedValue::Primitive(Primitive::Filesize(s.into())) } /// Helper for creating decimal values @@ -282,7 +282,7 @@ impl Value { UntaggedValue::Primitive(Primitive::Boolean(x)) => format!("{}", x), UntaggedValue::Primitive(Primitive::Decimal(x)) => format!("{}", x), UntaggedValue::Primitive(Primitive::Int(x)) => format!("{}", x), - UntaggedValue::Primitive(Primitive::Bytes(x)) => format!("{}", x), + UntaggedValue::Primitive(Primitive::Filesize(x)) => format!("{}", x), UntaggedValue::Primitive(Primitive::Path(x)) => format!("{}", x.display()), UntaggedValue::Primitive(Primitive::ColumnPath(path)) => { let joined = path diff --git a/crates/nu-protocol/src/value/debug.rs b/crates/nu-protocol/src/value/debug.rs index 7a46d098c..573db8a55 100644 --- a/crates/nu-protocol/src/value/debug.rs +++ b/crates/nu-protocol/src/value/debug.rs @@ -33,7 +33,7 @@ impl PrettyType for Primitive { Primitive::Int(_) => ty("integer"), Primitive::Range(_) => ty("range"), Primitive::Decimal(_) => ty("decimal"), - Primitive::Bytes(_) => ty("bytesize"), + Primitive::Filesize(_) => ty("filesize"), Primitive::String(_) => ty("string"), Primitive::Line(_) => ty("line"), Primitive::ColumnPath(_) => ty("column-path"), @@ -71,7 +71,7 @@ impl PrettyDebug for Primitive { .group(), ) } - Primitive::Bytes(bytes) => primitive_doc(bytes, "bytesize"), + Primitive::Filesize(bytes) => primitive_doc(bytes, "filesize"), Primitive::String(string) => prim(string), Primitive::Line(string) => prim(string), Primitive::ColumnPath(path) => path.pretty(), diff --git a/crates/nu-protocol/src/value/primitive.rs b/crates/nu-protocol/src/value/primitive.rs index 008215cc6..8a2b53263 100644 --- a/crates/nu-protocol/src/value/primitive.rs +++ b/crates/nu-protocol/src/value/primitive.rs @@ -31,7 +31,7 @@ pub enum Primitive { #[serde(with = "serde_bigdecimal")] Decimal(BigDecimal), /// A count in the number of bytes, used as a filesize - Bytes(u64), + Filesize(u64), /// A string value String(String), /// A string value with an implied carriage return (or cr/lf) ending @@ -143,7 +143,7 @@ impl num_traits::Zero for Primitive { match self { Primitive::Int(int) => int.is_zero(), Primitive::Decimal(decimal) => decimal.is_zero(), - Primitive::Bytes(size) => size.is_zero(), + Primitive::Filesize(num_bytes) => num_bytes.is_zero(), _ => false, } } @@ -164,25 +164,25 @@ impl std::ops::Add for Primitive { (Primitive::Decimal(left), Primitive::Int(right)) => { Primitive::Decimal(left + BigDecimal::from(right)) } - (Primitive::Bytes(left), right) => match right { - Primitive::Bytes(right) => Primitive::Bytes(left + right), + (Primitive::Filesize(left), right) => match right { + Primitive::Filesize(right) => Primitive::Filesize(left + right), Primitive::Int(right) => { - Primitive::Bytes(left + right.to_u64().unwrap_or_else(|| 0 as u64)) + Primitive::Filesize(left + right.to_u64().unwrap_or_else(|| 0 as u64)) } Primitive::Decimal(right) => { - Primitive::Bytes(left + right.to_u64().unwrap_or_else(|| 0 as u64)) + Primitive::Filesize(left + right.to_u64().unwrap_or_else(|| 0 as u64)) } - _ => Primitive::Bytes(left), + _ => Primitive::Filesize(left), }, - (left, Primitive::Bytes(right)) => match left { - Primitive::Bytes(left) => Primitive::Bytes(left + right), + (left, Primitive::Filesize(right)) => match left { + Primitive::Filesize(left) => Primitive::Filesize(left + right), Primitive::Int(left) => { - Primitive::Bytes(left.to_u64().unwrap_or_else(|| 0 as u64) + right) + Primitive::Filesize(left.to_u64().unwrap_or_else(|| 0 as u64) + right) } Primitive::Decimal(left) => { - Primitive::Bytes(left.to_u64().unwrap_or_else(|| 0 as u64) + right) + Primitive::Filesize(left.to_u64().unwrap_or_else(|| 0 as u64) + right) } - _ => Primitive::Bytes(right), + _ => Primitive::Filesize(right), }, _ => Primitive::zero(), } @@ -270,7 +270,7 @@ impl ShellTypeName for Primitive { Primitive::Int(_) => "integer", Primitive::Range(_) => "range", Primitive::Decimal(_) => "decimal", - Primitive::Bytes(_) => "bytes", + Primitive::Filesize(_) => "filesize(in bytes)", Primitive::String(_) => "string", Primitive::Line(_) => "line", Primitive::ColumnPath(_) => "column path", @@ -293,8 +293,8 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S Primitive::BeginningOfStream => String::new(), Primitive::EndOfStream => String::new(), Primitive::Path(p) => format!("{}", p.display()), - Primitive::Bytes(b) => { - let byte = byte_unit::Byte::from_bytes(*b as u128); + Primitive::Filesize(num_bytes) => { + let byte = byte_unit::Byte::from_bytes(*num_bytes as u128); if byte.get_bytes() == 0u128 { return "—".to_string(); diff --git a/crates/nu-value-ext/src/lib.rs b/crates/nu-value-ext/src/lib.rs index 677dd7f2a..3c783bd95 100644 --- a/crates/nu-value-ext/src/lib.rs +++ b/crates/nu-value-ext/src/lib.rs @@ -563,7 +563,7 @@ pub fn as_string(value: &Value) -> Result { UntaggedValue::Primitive(Primitive::Boolean(x)) => Ok(format!("{}", x)), UntaggedValue::Primitive(Primitive::Decimal(x)) => Ok(format!("{}", x)), UntaggedValue::Primitive(Primitive::Int(x)) => Ok(format!("{}", x)), - UntaggedValue::Primitive(Primitive::Bytes(x)) => Ok(format!("{}", x)), + UntaggedValue::Primitive(Primitive::Filesize(x)) => Ok(format!("{}", x)), UntaggedValue::Primitive(Primitive::Path(x)) => Ok(format!("{}", x.display())), UntaggedValue::Primitive(Primitive::ColumnPath(path)) => { let joined = path diff --git a/crates/nu_plugin_inc/src/inc.rs b/crates/nu_plugin_inc/src/inc.rs index 666d4f2d6..467c27880 100644 --- a/crates/nu_plugin_inc/src/inc.rs +++ b/crates/nu_plugin_inc/src/inc.rs @@ -78,8 +78,8 @@ impl Inc { UntaggedValue::Primitive(Primitive::Int(i)) => { Ok(UntaggedValue::int(i + 1).into_value(value.tag())) } - UntaggedValue::Primitive(Primitive::Bytes(b)) => { - Ok(UntaggedValue::bytes(b + 1 as u64).into_value(value.tag())) + UntaggedValue::Primitive(Primitive::Filesize(b)) => { + Ok(UntaggedValue::filesize(b + 1 as u64).into_value(value.tag())) } UntaggedValue::Primitive(Primitive::String(ref s)) => { Ok(self.apply(&s)?.into_value(value.tag())) diff --git a/crates/nu_plugin_post/src/post.rs b/crates/nu_plugin_post/src/post.rs index 78090a51e..3ed7d7d88 100644 --- a/crates/nu_plugin_post/src/post.rs +++ b/crates/nu_plugin_post/src/post.rs @@ -347,7 +347,7 @@ pub async fn post( pub fn value_to_json_value(v: &Value) -> Result { Ok(match &v.value { UntaggedValue::Primitive(Primitive::Boolean(b)) => serde_json::Value::Bool(*b), - UntaggedValue::Primitive(Primitive::Bytes(b)) => serde_json::Value::Number( + UntaggedValue::Primitive(Primitive::Filesize(b)) => serde_json::Value::Number( serde_json::Number::from(b.to_u64().expect("What about really big numbers")), ), UntaggedValue::Primitive(Primitive::Duration(i)) => { diff --git a/crates/nu_plugin_ps/src/ps.rs b/crates/nu_plugin_ps/src/ps.rs index 53e7da246..cb80c0d9a 100644 --- a/crates/nu_plugin_ps/src/ps.rs +++ b/crates/nu_plugin_ps/src/ps.rs @@ -61,11 +61,11 @@ pub async fn ps(tag: Tag, full: bool) -> Result, ShellError> { dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::())); dict.insert_untagged( "mem", - UntaggedValue::bytes(memory.rss().get::()), + UntaggedValue::filesize(memory.rss().get::()), ); dict.insert_untagged( "virtual", - UntaggedValue::bytes(memory.vms().get::()), + UntaggedValue::filesize(memory.vms().get::()), ); if full { if let Ok(parent_pid) = process.parent_pid().await { diff --git a/crates/nu_plugin_sys/src/sys.rs b/crates/nu_plugin_sys/src/sys.rs index 827bf49ee..99651bcc5 100644 --- a/crates/nu_plugin_sys/src/sys.rs +++ b/crates/nu_plugin_sys/src/sys.rs @@ -57,22 +57,22 @@ async fn mem(tag: Tag) -> Value { if let Ok(memory) = memory_result { dict.insert_untagged( "total", - UntaggedValue::bytes(memory.total().get::()), + UntaggedValue::filesize(memory.total().get::()), ); dict.insert_untagged( "free", - UntaggedValue::bytes(memory.free().get::()), + UntaggedValue::filesize(memory.free().get::()), ); } if let Ok(swap) = swap_result { dict.insert_untagged( "swap total", - UntaggedValue::bytes(swap.total().get::()), + UntaggedValue::filesize(swap.total().get::()), ); dict.insert_untagged( "swap free", - UntaggedValue::bytes(swap.free().get::()), + UntaggedValue::filesize(swap.free().get::()), ); } @@ -160,15 +160,15 @@ async fn disks(tag: Tag) -> Result, ShellError> { if let Ok(usage) = disk::usage(part.mount_point().to_path_buf()).await { dict.insert_untagged( "total", - UntaggedValue::bytes(usage.total().get::()), + UntaggedValue::filesize(usage.total().get::()), ); dict.insert_untagged( "used", - UntaggedValue::bytes(usage.used().get::()), + UntaggedValue::filesize(usage.used().get::()), ); dict.insert_untagged( "free", - UntaggedValue::bytes(usage.free().get::()), + UntaggedValue::filesize(usage.free().get::()), ); } @@ -295,11 +295,11 @@ async fn net(tag: Tag) -> Result, ShellError> { network_idx.insert_untagged("name", UntaggedValue::string(nic.interface())); network_idx.insert_untagged( "sent", - UntaggedValue::bytes(nic.bytes_sent().get::()), + UntaggedValue::filesize(nic.bytes_sent().get::()), ); network_idx.insert_untagged( "recv", - UntaggedValue::bytes(nic.bytes_recv().get::()), + UntaggedValue::filesize(nic.bytes_recv().get::()), ); output.push(network_idx.into_value()); }