-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Prompted by https://discord.com/channels/601130461678272522/615329862395101194/1050693116501426216 # User-Facing Changes New command `math tau` and endless agony whether to use `math pi` or `math tau` # Tests + Formatting Example test
- Loading branch information
1 parent
b938ade
commit b4529a2
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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 tau" | ||
} | ||
|
||
fn signature(&self) -> Signature { | ||
Signature::build("math tau") | ||
.input_output_types(vec![(Type::Any, Type::Float)]) | ||
.category(Category::Math) | ||
} | ||
|
||
fn usage(&self) -> &str { | ||
"Returns the mathematical constant τ." | ||
} | ||
|
||
fn search_terms(&self) -> Vec<&str> { | ||
vec!["trigonometry", "constant"] | ||
} | ||
|
||
#[allow(clippy::approx_constant)] | ||
fn examples(&self) -> Vec<Example> { | ||
vec![Example { | ||
example: "(math tau) / 2", | ||
description: "Compare π and τ", | ||
result: Some(Value::test_float(std::f64::consts::PI)), | ||
}] | ||
} | ||
|
||
fn run( | ||
&self, | ||
_engine_state: &EngineState, | ||
_stack: &mut Stack, | ||
call: &Call, | ||
_input: PipelineData, | ||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> { | ||
Ok(Value::Float { | ||
val: std::f64::consts::TAU, | ||
span: call.head, | ||
} | ||
.into_pipeline_data()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_examples() { | ||
use crate::test_examples; | ||
|
||
test_examples(SubCommand {}) | ||
} | ||
} |