forked from extern/nushell
still not working
This commit is contained in:
parent
b1d7e3aa49
commit
51bea2e884
@ -17,33 +17,36 @@ impl Command for SubCommand {
|
|||||||
"Returns absolute values of a list of numbers"
|
"Returns absolute values of a list of numbers"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, context: &EvaluationContext, call: &Call, input: Value) -> Result<Value, ShellError> {
|
fn run(&self, _context: &EvaluationContext, call: &Call, input: Value) -> Result<Value, ShellError> {
|
||||||
let mapped = input.map(move |val| match val.value {
|
let head = call.head;
|
||||||
|
input.map(head, move |val| match val {
|
||||||
Value::Int { val, span } => Value::int(val.abs(), span),
|
Value::Int { val, span } => Value::int(val.abs(), span),
|
||||||
Value::Float { val, span } => Value::Float{val: val.abs(), span: span},
|
Value::Float { val, span } => Value::Float{val: val.abs(), span: span},
|
||||||
Value::Duration { val, span } => Value::Duration{val: val.abs(), span: span},
|
Value::Duration { val, span } => Value::Duration{val: val.abs(), span: span},
|
||||||
other => abs_default(other)?,
|
other => abs_default(other, head),
|
||||||
});
|
})
|
||||||
Ok(mapped)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Get absolute of each value in a list of numbers",
|
description: "Get absolute of each value in a list of numbers",
|
||||||
example: "echo [-50 25] | math abs",
|
example: "echo [-50 25] | math abs",
|
||||||
result: Some(vec![
|
result: Some(Value:: List {
|
||||||
Value::test_int(50),
|
vals: vec![
|
||||||
Value::test_int(25),
|
Value::test_int(50),
|
||||||
]),
|
Value::test_int(25),
|
||||||
|
],
|
||||||
|
span: Span::unknown(),
|
||||||
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn abs_default(_: Value) -> Result<Value, ShellError> {
|
fn abs_default(_: Value, head: Span) -> Value {
|
||||||
Value::Error(ShellError::unexpected(
|
Value::Error {error: ShellError::UnsupportedInput(
|
||||||
"Only numerical values are supported",
|
String::from("Only numerical values are supported"),
|
||||||
))
|
head
|
||||||
.into()
|
)}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
pub mod abs;
|
mod abs;
|
||||||
|
|
||||||
pub use abs::SubCommand as MathAbs;
|
pub use abs::SubCommand as MathAbs;
|
||||||
|
Loading…
Reference in New Issue
Block a user