mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 15:42:33 +02:00
Fix compilation errors
This commit is contained in:
@ -203,7 +203,7 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
|
|||||||
Value::string(raw_string.trim(), span)
|
Value::string(raw_string.trim(), span)
|
||||||
}
|
}
|
||||||
Value::Int { val, .. } => convert_to_smallest_number_type(*val, span),
|
Value::Int { val, .. } => convert_to_smallest_number_type(*val, span),
|
||||||
Value::Filesize { val, .. } => convert_to_smallest_number_type(*val, span),
|
Value::Filesize { val, .. } => convert_to_smallest_number_type(val.get(), span),
|
||||||
Value::Duration { val, .. } => convert_to_smallest_number_type(*val, span),
|
Value::Duration { val, .. } => convert_to_smallest_number_type(*val, span),
|
||||||
Value::String { val, .. } => {
|
Value::String { val, .. } => {
|
||||||
let raw_bytes = val.as_bytes();
|
let raw_bytes = val.as_bytes();
|
||||||
|
@ -66,7 +66,7 @@ fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value {
|
|||||||
match input {
|
match input {
|
||||||
Value::Float { val, .. } => fmt_it_64(*val, span),
|
Value::Float { val, .. } => fmt_it_64(*val, span),
|
||||||
Value::Int { val, .. } => fmt_it(*val, span),
|
Value::Int { val, .. } => fmt_it(*val, span),
|
||||||
Value::Filesize { val, .. } => fmt_it(*val, span),
|
Value::Filesize { val, .. } => fmt_it(val.get(), span),
|
||||||
// Propagate errors by explicitly matching them before the final case.
|
// Propagate errors by explicitly matching them before the final case.
|
||||||
Value::Error { .. } => input.clone(),
|
Value::Error { .. } => input.clone(),
|
||||||
other => Value::error(
|
other => Value::error(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use nu_protocol::{ShellError, Span, Value};
|
use nu_protocol::{Filesize, ShellError, Span, Value};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
/// A subset of [`Value`], which is hashable.
|
/// A subset of [`Value`], which is hashable.
|
||||||
@ -30,7 +30,7 @@ pub enum HashableValue {
|
|||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
Filesize {
|
Filesize {
|
||||||
val: i64,
|
val: Filesize,
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
Duration {
|
Duration {
|
||||||
@ -198,7 +198,10 @@ mod test {
|
|||||||
(Value::int(1, span), HashableValue::Int { val: 1, span }),
|
(Value::int(1, span), HashableValue::Int { val: 1, span }),
|
||||||
(
|
(
|
||||||
Value::filesize(1, span),
|
Value::filesize(1, span),
|
||||||
HashableValue::Filesize { val: 1, span },
|
HashableValue::Filesize {
|
||||||
|
val: 1.into(),
|
||||||
|
span,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Value::duration(1, span),
|
Value::duration(1, span),
|
||||||
|
@ -167,7 +167,7 @@ fn fill(
|
|||||||
fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||||
match input {
|
match input {
|
||||||
Value::Int { val, .. } => fill_int(*val, args, span),
|
Value::Int { val, .. } => fill_int(*val, args, span),
|
||||||
Value::Filesize { val, .. } => fill_int(*val, args, span),
|
Value::Filesize { val, .. } => fill_int(val.get(), args, span),
|
||||||
Value::Float { val, .. } => fill_float(*val, args, span),
|
Value::Float { val, .. } => fill_float(*val, args, span),
|
||||||
Value::String { val, .. } => fill_string(val, args, span),
|
Value::String { val, .. } => fill_string(val, args, span),
|
||||||
// Propagate errors by explicitly matching them before the final case.
|
// Propagate errors by explicitly matching them before the final case.
|
||||||
|
@ -147,7 +147,7 @@ pub fn action(input: &Value, _args: &Arguments, span: Span) -> Value {
|
|||||||
Value::Binary { .. } => input.clone(),
|
Value::Binary { .. } => input.clone(),
|
||||||
Value::Int { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
Value::Int { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
||||||
Value::Float { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
Value::Float { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
||||||
Value::Filesize { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
Value::Filesize { val, .. } => Value::binary(val.get().to_ne_bytes().to_vec(), span),
|
||||||
Value::String { val, .. } => Value::binary(val.as_bytes().to_vec(), span),
|
Value::String { val, .. } => Value::binary(val.as_bytes().to_vec(), span),
|
||||||
Value::Bool { val, .. } => Value::binary(i64::from(*val).to_ne_bytes().to_vec(), span),
|
Value::Bool { val, .. } => Value::binary(i64::from(*val).to_ne_bytes().to_vec(), span),
|
||||||
Value::Duration { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
Value::Duration { val, .. } => Value::binary(val.to_ne_bytes().to_vec(), span),
|
||||||
|
@ -253,7 +253,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
|||||||
convert_int(input, span, radix)
|
convert_int(input, span, radix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::Filesize { val, .. } => Value::int(*val, span),
|
Value::Filesize { val, .. } => Value::int(val.get(), span),
|
||||||
Value::Float { val, .. } => Value::int(
|
Value::Float { val, .. } => Value::int(
|
||||||
{
|
{
|
||||||
if radix == 10 {
|
if radix == 10 {
|
||||||
|
@ -421,7 +421,7 @@ pub fn value_to_sql(value: Value) -> Result<Box<dyn rusqlite::ToSql>, ShellError
|
|||||||
Value::Bool { val, .. } => Box::new(val),
|
Value::Bool { val, .. } => Box::new(val),
|
||||||
Value::Int { val, .. } => Box::new(val),
|
Value::Int { val, .. } => Box::new(val),
|
||||||
Value::Float { val, .. } => Box::new(val),
|
Value::Float { val, .. } => Box::new(val),
|
||||||
Value::Filesize { val, .. } => Box::new(val),
|
Value::Filesize { val, .. } => Box::new(val.get()),
|
||||||
Value::Duration { val, .. } => Box::new(val),
|
Value::Duration { val, .. } => Box::new(val),
|
||||||
Value::Date { val, .. } => Box::new(val),
|
Value::Date { val, .. } => Box::new(val),
|
||||||
Value::String { val, .. } => Box::new(val),
|
Value::String { val, .. } => Box::new(val),
|
||||||
|
@ -109,7 +109,7 @@ pub fn value_to_json_value(v: &Value) -> Result<nu_json::Value, ShellError> {
|
|||||||
let span = v.span();
|
let span = v.span();
|
||||||
Ok(match v {
|
Ok(match v {
|
||||||
Value::Bool { val, .. } => nu_json::Value::Bool(*val),
|
Value::Bool { val, .. } => nu_json::Value::Bool(*val),
|
||||||
Value::Filesize { val, .. } => nu_json::Value::I64(*val),
|
Value::Filesize { val, .. } => nu_json::Value::I64(val.get()),
|
||||||
Value::Duration { val, .. } => nu_json::Value::I64(*val),
|
Value::Duration { val, .. } => nu_json::Value::I64(*val),
|
||||||
Value::Date { val, .. } => nu_json::Value::String(val.to_string()),
|
Value::Date { val, .. } => nu_json::Value::String(val.to_string()),
|
||||||
Value::Float { val, .. } => nu_json::Value::F64(*val),
|
Value::Float { val, .. } => nu_json::Value::F64(*val),
|
||||||
|
@ -168,7 +168,7 @@ pub(crate) fn write_value(
|
|||||||
mp::write_f64(out, *val).err_span(span)?;
|
mp::write_f64(out, *val).err_span(span)?;
|
||||||
}
|
}
|
||||||
Value::Filesize { val, .. } => {
|
Value::Filesize { val, .. } => {
|
||||||
mp::write_sint(out, *val).err_span(span)?;
|
mp::write_sint(out, val.get()).err_span(span)?;
|
||||||
}
|
}
|
||||||
Value::Duration { val, .. } => {
|
Value::Duration { val, .. } => {
|
||||||
mp::write_sint(out, *val).err_span(span)?;
|
mp::write_sint(out, *val).err_span(span)?;
|
||||||
|
@ -47,7 +47,7 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result<toml::Value, ShellErr
|
|||||||
Ok(match &v {
|
Ok(match &v {
|
||||||
Value::Bool { val, .. } => toml::Value::Boolean(*val),
|
Value::Bool { val, .. } => toml::Value::Boolean(*val),
|
||||||
Value::Int { val, .. } => toml::Value::Integer(*val),
|
Value::Int { val, .. } => toml::Value::Integer(*val),
|
||||||
Value::Filesize { val, .. } => toml::Value::Integer(*val),
|
Value::Filesize { val, .. } => toml::Value::Integer(val.get()),
|
||||||
Value::Duration { val, .. } => toml::Value::String(val.to_string()),
|
Value::Duration { val, .. } => toml::Value::String(val.to_string()),
|
||||||
Value::Date { val, .. } => toml::Value::Datetime(to_toml_datetime(val)),
|
Value::Date { val, .. } => toml::Value::Datetime(to_toml_datetime(val)),
|
||||||
Value::Range { .. } => toml::Value::String("<Range>".to_string()),
|
Value::Range { .. } => toml::Value::String("<Range>".to_string()),
|
||||||
|
@ -44,7 +44,9 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
|
|||||||
Ok(match &v {
|
Ok(match &v {
|
||||||
Value::Bool { val, .. } => serde_yaml::Value::Bool(*val),
|
Value::Bool { val, .. } => serde_yaml::Value::Bool(*val),
|
||||||
Value::Int { val, .. } => serde_yaml::Value::Number(serde_yaml::Number::from(*val)),
|
Value::Int { val, .. } => serde_yaml::Value::Number(serde_yaml::Number::from(*val)),
|
||||||
Value::Filesize { val, .. } => serde_yaml::Value::Number(serde_yaml::Number::from(*val)),
|
Value::Filesize { val, .. } => {
|
||||||
|
serde_yaml::Value::Number(serde_yaml::Number::from(val.get()))
|
||||||
|
}
|
||||||
Value::Duration { val, .. } => serde_yaml::Value::String(val.to_string()),
|
Value::Duration { val, .. } => serde_yaml::Value::String(val.to_string()),
|
||||||
Value::Date { val, .. } => serde_yaml::Value::String(val.to_string()),
|
Value::Date { val, .. } => serde_yaml::Value::String(val.to_string()),
|
||||||
Value::Range { .. } => serde_yaml::Value::Null,
|
Value::Range { .. } => serde_yaml::Value::Null,
|
||||||
|
@ -90,7 +90,7 @@ pub fn average(values: &[Value], span: Span, head: Span) -> Result<Value, ShellE
|
|||||||
let total = &sum(Value::int(0, head), values.to_vec(), span, head)?;
|
let total = &sum(Value::int(0, head), values.to_vec(), span, head)?;
|
||||||
let span = total.span();
|
let span = total.span();
|
||||||
match total {
|
match total {
|
||||||
Value::Filesize { val, .. } => Ok(Value::filesize(val / values.len() as i64, span)),
|
Value::Filesize { val, .. } => Ok(Value::filesize(val.get() / values.len() as i64, span)),
|
||||||
Value::Duration { val, .. } => Ok(Value::duration(val / values.len() as i64, span)),
|
Value::Duration { val, .. } => Ok(Value::duration(val / values.len() as i64, span)),
|
||||||
_ => total.div(head, &Value::int(values.len() as i64, head), head),
|
_ => total.div(head, &Value::int(values.len() as i64, head), head),
|
||||||
}
|
}
|
||||||
|
@ -142,9 +142,10 @@ pub fn mode(values: &[Value], _span: Span, head: Span) -> Result<Value, ShellErr
|
|||||||
Value::Float { val, .. } => {
|
Value::Float { val, .. } => {
|
||||||
Ok(HashableType::new(val.to_ne_bytes(), NumberTypes::Float))
|
Ok(HashableType::new(val.to_ne_bytes(), NumberTypes::Float))
|
||||||
}
|
}
|
||||||
Value::Filesize { val, .. } => {
|
Value::Filesize { val, .. } => Ok(HashableType::new(
|
||||||
Ok(HashableType::new(val.to_ne_bytes(), NumberTypes::Filesize))
|
val.get().to_ne_bytes(),
|
||||||
}
|
NumberTypes::Filesize,
|
||||||
|
)),
|
||||||
Value::Error { error, .. } => Err(*error.clone()),
|
Value::Error { error, .. } => Err(*error.clone()),
|
||||||
other => Err(ShellError::UnsupportedInput {
|
other => Err(ShellError::UnsupportedInput {
|
||||||
msg: "Unable to give a result with this input".to_string(),
|
msg: "Unable to give a result with this input".to_string(),
|
||||||
|
@ -11,9 +11,9 @@ use itertools::Itertools;
|
|||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_engine::DIR_VAR_PARSER_INFO;
|
use nu_engine::DIR_VAR_PARSER_INFO;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::*, engine::StateWorkingSet, eval_const::eval_constant, BlockId, DeclId, DidYouMean, Flag,
|
ast::*, engine::StateWorkingSet, eval_const::eval_constant, BlockId, DeclId, DidYouMean,
|
||||||
ParseError, PositionalArg, Signature, Span, Spanned, SyntaxShape, Type, VarId, ENV_VARIABLE_ID,
|
FilesizeUnit, Flag, ParseError, PositionalArg, Signature, Span, Spanned, SyntaxShape, Type,
|
||||||
IN_VARIABLE_ID,
|
VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
@ -2572,19 +2572,67 @@ pub fn parse_unit_value<'res>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const FILESIZE_UNIT_GROUPS: &[UnitGroup] = &[
|
pub const FILESIZE_UNIT_GROUPS: &[UnitGroup] = &[
|
||||||
(Unit::Kilobyte, "KB", Some((Unit::Byte, 1000))),
|
(
|
||||||
(Unit::Megabyte, "MB", Some((Unit::Kilobyte, 1000))),
|
Unit::Filesize(FilesizeUnit::KB),
|
||||||
(Unit::Gigabyte, "GB", Some((Unit::Megabyte, 1000))),
|
"KB",
|
||||||
(Unit::Terabyte, "TB", Some((Unit::Gigabyte, 1000))),
|
Some((Unit::Filesize(FilesizeUnit::B), 1000)),
|
||||||
(Unit::Petabyte, "PB", Some((Unit::Terabyte, 1000))),
|
),
|
||||||
(Unit::Exabyte, "EB", Some((Unit::Petabyte, 1000))),
|
(
|
||||||
(Unit::Kibibyte, "KIB", Some((Unit::Byte, 1024))),
|
Unit::Filesize(FilesizeUnit::MB),
|
||||||
(Unit::Mebibyte, "MIB", Some((Unit::Kibibyte, 1024))),
|
"MB",
|
||||||
(Unit::Gibibyte, "GIB", Some((Unit::Mebibyte, 1024))),
|
Some((Unit::Filesize(FilesizeUnit::KB), 1000)),
|
||||||
(Unit::Tebibyte, "TIB", Some((Unit::Gibibyte, 1024))),
|
),
|
||||||
(Unit::Pebibyte, "PIB", Some((Unit::Tebibyte, 1024))),
|
(
|
||||||
(Unit::Exbibyte, "EIB", Some((Unit::Pebibyte, 1024))),
|
Unit::Filesize(FilesizeUnit::GB),
|
||||||
(Unit::Byte, "B", None),
|
"GB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::MB), 1000)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::TB),
|
||||||
|
"TB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::GB), 1000)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::PB),
|
||||||
|
"PB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::TB), 1000)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::EB),
|
||||||
|
"EB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::PB), 1000)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::KiB),
|
||||||
|
"KIB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::B), 1024)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::MiB),
|
||||||
|
"MIB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::KiB), 1024)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::GiB),
|
||||||
|
"GIB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::MiB), 1024)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::TiB),
|
||||||
|
"TIB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::GiB), 1024)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::PiB),
|
||||||
|
"PIB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::TiB), 1024)),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Unit::Filesize(FilesizeUnit::EiB),
|
||||||
|
"EIB",
|
||||||
|
Some((Unit::Filesize(FilesizeUnit::EiB), 1024)),
|
||||||
|
),
|
||||||
|
(Unit::Filesize(FilesizeUnit::B), "B", None),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const DURATION_UNIT_GROUPS: &[UnitGroup] = &[
|
pub const DURATION_UNIT_GROUPS: &[UnitGroup] = &[
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use std::{fmt, sync::Arc};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{CellPath, Expression, Operator, Pattern, RangeInclusion},
|
ast::{CellPath, Expression, Operator, Pattern, RangeInclusion},
|
||||||
engine::EngineState,
|
engine::EngineState,
|
||||||
BlockId, DeclId, RegId, Span, Value, VarId,
|
BlockId, DeclId, Filesize, RegId, Span, Value, VarId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{fmt, sync::Arc};
|
||||||
|
|
||||||
mod call;
|
mod call;
|
||||||
mod display;
|
mod display;
|
||||||
@ -397,7 +395,7 @@ pub enum Literal {
|
|||||||
Bool(bool),
|
Bool(bool),
|
||||||
Int(i64),
|
Int(i64),
|
||||||
Float(f64),
|
Float(f64),
|
||||||
Filesize(i64),
|
Filesize(Filesize),
|
||||||
Duration(i64),
|
Duration(i64),
|
||||||
Binary(DataSlice),
|
Binary(DataSlice),
|
||||||
Block(BlockId),
|
Block(BlockId),
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
use std::time::SystemTime;
|
use crate::FormatCmdsPlugin;
|
||||||
|
|
||||||
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand, SimplePluginCommand};
|
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand, SimplePluginCommand};
|
||||||
use nu_protocol::{Category, Example, LabeledError, Record, Signature, Span, Value as NuValue};
|
use nu_protocol::{Category, Example, LabeledError, Record, Signature, Span, Value as NuValue};
|
||||||
use plist::{Integer, Value as PlistValue};
|
use plist::Value as PlistValue;
|
||||||
|
use std::time::SystemTime;
|
||||||
use crate::FormatCmdsPlugin;
|
|
||||||
|
|
||||||
pub(crate) struct IntoPlist;
|
pub(crate) struct IntoPlist;
|
||||||
|
|
||||||
@ -68,7 +66,7 @@ fn convert_nu_value(nu_val: &NuValue) -> Result<PlistValue, LabeledError> {
|
|||||||
NuValue::String { val, .. } => Ok(PlistValue::String(val.to_owned())),
|
NuValue::String { val, .. } => Ok(PlistValue::String(val.to_owned())),
|
||||||
NuValue::Bool { val, .. } => Ok(PlistValue::Boolean(*val)),
|
NuValue::Bool { val, .. } => Ok(PlistValue::Boolean(*val)),
|
||||||
NuValue::Float { val, .. } => Ok(PlistValue::Real(*val)),
|
NuValue::Float { val, .. } => Ok(PlistValue::Real(*val)),
|
||||||
NuValue::Int { val, .. } => Ok(PlistValue::Integer(Into::<Integer>::into(*val))),
|
NuValue::Int { val, .. } => Ok(PlistValue::Integer((*val).into())),
|
||||||
NuValue::Binary { val, .. } => Ok(PlistValue::Data(val.to_owned())),
|
NuValue::Binary { val, .. } => Ok(PlistValue::Data(val.to_owned())),
|
||||||
NuValue::Record { val, .. } => convert_nu_dict(val),
|
NuValue::Record { val, .. } => convert_nu_dict(val),
|
||||||
NuValue::List { vals, .. } => Ok(PlistValue::Array(
|
NuValue::List { vals, .. } => Ok(PlistValue::Array(
|
||||||
@ -77,7 +75,7 @@ fn convert_nu_value(nu_val: &NuValue) -> Result<PlistValue, LabeledError> {
|
|||||||
.collect::<Result<_, _>>()?,
|
.collect::<Result<_, _>>()?,
|
||||||
)),
|
)),
|
||||||
NuValue::Date { val, .. } => Ok(PlistValue::Date(SystemTime::from(val.to_owned()).into())),
|
NuValue::Date { val, .. } => Ok(PlistValue::Date(SystemTime::from(val.to_owned()).into())),
|
||||||
NuValue::Filesize { val, .. } => Ok(PlistValue::Integer(Into::<Integer>::into(*val))),
|
NuValue::Filesize { val, .. } => Ok(PlistValue::Integer(val.get().into())),
|
||||||
_ => Err(build_label_error(
|
_ => Err(build_label_error(
|
||||||
format!("{:?} is not convertible", nu_val),
|
format!("{:?} is not convertible", nu_val),
|
||||||
span,
|
span,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{Expr, Expression, ListItem, RecordItem},
|
ast::{Expr, Expression, ListItem, RecordItem},
|
||||||
engine::{EngineState, StateWorkingSet},
|
engine::{EngineState, StateWorkingSet},
|
||||||
Range, Record, ShellError, Span, Type, Unit, Value,
|
Filesize, IntoValue, Range, Record, ShellError, Span, Type, Unit, Value,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -407,32 +407,15 @@ fn convert_to_value(
|
|||||||
};
|
};
|
||||||
|
|
||||||
match value.unit.item {
|
match value.unit.item {
|
||||||
Unit::Byte => Ok(Value::filesize(size, span)),
|
Unit::Filesize(unit) => match Filesize::from_unit(size, unit) {
|
||||||
Unit::Kilobyte => Ok(Value::filesize(size * 1000, span)),
|
Some(val) => Ok(val.into_value(span)),
|
||||||
Unit::Megabyte => Ok(Value::filesize(size * 1000 * 1000, span)),
|
None => Err(ShellError::OutsideSpannedLabeledError {
|
||||||
Unit::Gigabyte => Ok(Value::filesize(size * 1000 * 1000 * 1000, span)),
|
src: original_text.into(),
|
||||||
Unit::Terabyte => Ok(Value::filesize(size * 1000 * 1000 * 1000 * 1000, span)),
|
error: "filesize too large".into(),
|
||||||
Unit::Petabyte => Ok(Value::filesize(
|
msg: "filesize too large".into(),
|
||||||
size * 1000 * 1000 * 1000 * 1000 * 1000,
|
span: expr.span,
|
||||||
span,
|
}),
|
||||||
)),
|
},
|
||||||
Unit::Exabyte => Ok(Value::filesize(
|
|
||||||
size * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
|
||||||
span,
|
|
||||||
)),
|
|
||||||
|
|
||||||
Unit::Kibibyte => Ok(Value::filesize(size * 1024, span)),
|
|
||||||
Unit::Mebibyte => Ok(Value::filesize(size * 1024 * 1024, span)),
|
|
||||||
Unit::Gibibyte => Ok(Value::filesize(size * 1024 * 1024 * 1024, span)),
|
|
||||||
Unit::Tebibyte => Ok(Value::filesize(size * 1024 * 1024 * 1024 * 1024, span)),
|
|
||||||
Unit::Pebibyte => Ok(Value::filesize(
|
|
||||||
size * 1024 * 1024 * 1024 * 1024 * 1024,
|
|
||||||
span,
|
|
||||||
)),
|
|
||||||
Unit::Exbibyte => Ok(Value::filesize(
|
|
||||||
size * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
|
|
||||||
span,
|
|
||||||
)),
|
|
||||||
|
|
||||||
Unit::Nanosecond => Ok(Value::duration(size, span)),
|
Unit::Nanosecond => Ok(Value::duration(size, span)),
|
||||||
Unit::Microsecond => Ok(Value::duration(size * 1000, span)),
|
Unit::Microsecond => Ok(Value::duration(size * 1000, span)),
|
||||||
|
Reference in New Issue
Block a user