Switch to "engine-p" (#3270)

* WIP

* WIP

* first builds

* Tests pass
This commit is contained in:
Jonathan Turner
2021-04-07 04:19:43 +12:00
committed by GitHub
parent ad1c4f5e39
commit 073e5727c6
262 changed files with 2269 additions and 2660 deletions

View File

@ -12,7 +12,6 @@ pub struct BoolArgs {
bias: Option<Tagged<f64>>,
}
#[async_trait]
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random bool"
@ -31,8 +30,8 @@ impl WholeStreamCommand for SubCommand {
"Generate a random boolean value"
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
bool_command(args).await
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
bool_command(args)
}
fn examples(&self) -> Vec<Example> {
@ -51,8 +50,8 @@ impl WholeStreamCommand for SubCommand {
}
}
pub async fn bool_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (BoolArgs { bias }, _) = args.process().await?;
pub fn bool_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (BoolArgs { bias }, _) = args.process()?;
let mut probability = 0.5;

View File

@ -15,7 +15,6 @@ pub struct CharsArgs {
const DEFAULT_CHARS_LENGTH: u32 = 25;
#[async_trait]
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random chars"
@ -34,8 +33,8 @@ impl WholeStreamCommand for SubCommand {
"Generate random chars"
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
chars(args).await
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
chars(args)
}
fn examples(&self) -> Vec<Example> {
@ -54,8 +53,8 @@ impl WholeStreamCommand for SubCommand {
}
}
pub async fn chars(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (CharsArgs { length }, _) = args.process().await?;
pub fn chars(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (CharsArgs { length }, _) = args.process()?;
let chars_length = length.map_or(DEFAULT_CHARS_LENGTH, |l| l.item);

View File

@ -5,7 +5,6 @@ use nu_protocol::{ReturnSuccess, Signature, UntaggedValue};
pub struct Command;
#[async_trait]
impl WholeStreamCommand for Command {
fn name(&self) -> &str {
"random"
@ -19,7 +18,7 @@ impl WholeStreamCommand for Command {
"Generate random values."
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::one(Ok(ReturnSuccess::Value(
UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()),
))))

View File

@ -14,7 +14,6 @@ pub struct DecimalArgs {
range: Option<Tagged<NumericRange>>,
}
#[async_trait]
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random decimal"
@ -28,8 +27,8 @@ impl WholeStreamCommand for SubCommand {
"Generate a random decimal within a range [min..max]"
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
decimal(args).await
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
decimal(args)
}
fn examples(&self) -> Vec<Example> {
@ -58,8 +57,8 @@ impl WholeStreamCommand for SubCommand {
}
}
pub async fn decimal(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (DecimalArgs { range }, _) = args.process().await?;
pub fn decimal(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (DecimalArgs { range }, _) = args.process()?;
let (min, max) = if let Some(range) = &range {
(range.item.min() as f64, range.item.max() as f64)

View File

@ -13,7 +13,6 @@ pub struct DiceArgs {
sides: Option<Tagged<u32>>,
}
#[async_trait]
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random dice"
@ -39,8 +38,8 @@ impl WholeStreamCommand for SubCommand {
"Generate a random dice roll"
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
dice(args).await
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
dice(args)
}
fn examples(&self) -> Vec<Example> {
@ -59,9 +58,9 @@ impl WholeStreamCommand for SubCommand {
}
}
pub async fn dice(args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn dice(args: CommandArgs) -> Result<OutputStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let (DiceArgs { dice, sides }, _) = args.process().await?;
let (DiceArgs { dice, sides }, _) = args.process()?;
let dice = if let Some(dice_tagged) = dice {
*dice_tagged
@ -80,7 +79,7 @@ pub async fn dice(args: CommandArgs) -> Result<OutputStream, ShellError> {
UntaggedValue::int(thread_rng.gen_range(1, sides + 1)).into_value(tag.clone())
});
Ok(futures::stream::iter(iter).to_output_stream())
Ok((iter).to_output_stream())
}
#[cfg(test)]

View File

@ -14,7 +14,6 @@ pub struct IntegerArgs {
range: Option<Tagged<NumericRange>>,
}
#[async_trait]
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random integer"
@ -28,8 +27,8 @@ impl WholeStreamCommand for SubCommand {
"Generate a random integer [min..max]"
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
integer(args).await
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
integer(args)
}
fn examples(&self) -> Vec<Example> {
@ -58,8 +57,8 @@ impl WholeStreamCommand for SubCommand {
}
}
pub async fn integer(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (IntegerArgs { range }, _) = args.process().await?;
pub fn integer(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (IntegerArgs { range }, _) = args.process()?;
let (min, max) = if let Some(range) = &range {
(range.item.min(), range.item.max())

View File

@ -6,7 +6,6 @@ use uuid_crate::Uuid;
pub struct SubCommand;
#[async_trait]
impl WholeStreamCommand for SubCommand {
fn name(&self) -> &str {
"random uuid"
@ -20,8 +19,8 @@ impl WholeStreamCommand for SubCommand {
"Generate a random uuid4 string"
}
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
uuid(args).await
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
uuid(args)
}
fn examples(&self) -> Vec<Example> {
@ -33,7 +32,7 @@ impl WholeStreamCommand for SubCommand {
}
}
pub async fn uuid(_args: CommandArgs) -> Result<OutputStream, ShellError> {
pub fn uuid(_args: CommandArgs) -> Result<OutputStream, ShellError> {
let uuid_4 = Uuid::new_v4().to_hyphenated().to_string();
Ok(OutputStream::one(ReturnSuccess::value(uuid_4)))