use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Type, Value};
#[derive(Clone)]
pub struct SubCommand;
impl Command for SubCommand {
fn name(&self) -> &str {
"math e"
}
fn signature(&self) -> Signature {
Signature::build("math e")
.input_output_types(vec![(Type::Any, Type::Float)])
.category(Category::Math)
}
fn usage(&self) -> &str {
"Returns the mathematical constant e (exp(1)/'1 | math exp')."
}
fn search_terms(&self) -> Vec<&str> {
vec!["euler", "constant"]
}
#[allow(clippy::approx_constant)]
fn examples(&self) -> Vec<Example> {
vec![Example {
example: "math e | math round --precision 3",
description: "Get the first three decimal digits of e",
result: Some(Value::test_float(2.718)),
}]
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(Value::float(std::f64::consts::E, call.head).into_pipeline_data())
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(SubCommand {})
}
}