forked from extern/nushell
Rename 'bytes' to 'filesize' (#2153)
This commit is contained in:
@ -357,12 +357,12 @@ impl From<DirInfo> 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<FileInfo> 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);
|
||||
|
||||
|
@ -71,7 +71,7 @@ pub fn average(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
|
||||
|
||||
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<Value, ShellError> {
|
||||
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",
|
||||
|
@ -134,7 +134,7 @@ fn compute_average(values: &[Value], name: impl Into<Tag>) -> Result<Value, Shel
|
||||
|
||||
match total {
|
||||
Value {
|
||||
value: UntaggedValue::Primitive(Primitive::Bytes(num)),
|
||||
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
|
||||
..
|
||||
} => {
|
||||
let left = UntaggedValue::from(Primitive::Int(num.into()));
|
||||
@ -144,7 +144,7 @@ fn compute_average(values: &[Value], name: impl Into<Tag>) -> Result<Value, Shel
|
||||
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 median of non-numeric or unrelated types",
|
||||
|
@ -41,7 +41,7 @@ pub fn value_to_bson_value(v: &Value) -> Result<Bson, ShellError> {
|
||||
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?"),
|
||||
|
@ -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<String, ShellError> {
|
||||
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(_))
|
||||
|
@ -62,7 +62,7 @@ impl WholeStreamCommand for ToJSON {
|
||||
pub fn value_to_json_value(v: &Value) -> Result<serde_json::Value, ShellError> {
|
||||
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)) => {
|
||||
|
@ -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("'", "''")),
|
||||
|
@ -44,7 +44,7 @@ impl WholeStreamCommand for ToTOML {
|
||||
fn helper(v: &Value) -> Result<toml::Value, ShellError> {
|
||||
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) => {
|
||||
|
@ -31,7 +31,7 @@ impl WholeStreamCommand for ToYAML {
|
||||
pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
|
||||
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",
|
||||
|
@ -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(_)
|
||||
|
@ -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),
|
||||
|
@ -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()),
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,9 @@ pub fn number(number: impl Into<Number>) -> 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(),
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ pub fn compute_values(
|
||||
) -> Result<UntaggedValue, (&'static str, &'static str)> {
|
||||
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))),
|
||||
|
Reference in New Issue
Block a user