Merge stream_example into example plugin and clean up names (#12234)

# Description

As suggested by @WindSoilder, since plugins can now contain both simple
commands that produce `Value` and commands that produce `PipelineData`
without having to choose one or the other for the whole plugin, this
change merges `stream_example` into `example`.

# User-Facing Changes

All of the example plugins are renamed.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

- [ ] Check nushell/nushell.github.io for any docs that match the
command names changed
This commit is contained in:
Devyn Cairns 2024-03-19 10:36:46 -07:00 committed by GitHub
parent 02551c416c
commit a29efe28f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 197 additions and 305 deletions

8
Cargo.lock generated
View File

@ -3228,14 +3228,6 @@ dependencies = [
"sxd-xpath",
]
[[package]]
name = "nu_plugin_stream_example"
version = "0.91.1"
dependencies = [
"nu-plugin",
"nu-protocol",
]
[[package]]
name = "num"
version = "0.4.1"

View File

@ -43,7 +43,6 @@ members = [
"crates/nu_plugin_inc",
"crates/nu_plugin_gstat",
"crates/nu_plugin_example",
"crates/nu_plugin_stream_example",
"crates/nu_plugin_query",
"crates/nu_plugin_custom_values",
"crates/nu_plugin_formats",

View File

@ -29,6 +29,6 @@ $env.config = {
To list plugin values run:
```nushell
nu-example-config
example config
```

View File

@ -1,16 +1,16 @@
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, PluginCommand};
use nu_protocol::{Category, PipelineData, PluginExample, PluginSignature, RawStream, Type, Value};
use crate::StreamExample;
use crate::Example;
/// `<list<string>> | stream_example collect-external`
/// `<list<string>> | example collect-external`
pub struct CollectExternal;
impl PluginCommand for CollectExternal {
type Plugin = StreamExample;
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("stream_example collect-external")
PluginSignature::build("example collect-external")
.usage("Example transformer to raw external stream")
.search_terms(vec!["example".into()])
.input_output_types(vec![
@ -18,7 +18,7 @@ impl PluginCommand for CollectExternal {
(Type::List(Type::Binary.into()), Type::Binary),
])
.plugin_examples(vec![PluginExample {
example: "[a b] | stream_example collect-external".into(),
example: "[a b] | example collect-external".into(),
description: "collect strings into one stream".into(),
result: Some(Value::test_string("ab")),
}])
@ -27,7 +27,7 @@ impl PluginCommand for CollectExternal {
fn run(
&self,
_plugin: &StreamExample,
_plugin: &Example,
_engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,

View File

@ -3,13 +3,13 @@ use nu_protocol::{Category, PluginSignature, Type, Value};
use crate::Example;
pub struct NuExampleConfig;
pub struct Config;
impl SimplePluginCommand for NuExampleConfig {
impl SimplePluginCommand for Config {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("nu-example-config")
PluginSignature::build("example config")
.usage("Show plugin configuration")
.extra_usage("The configuration is set under $env.config.plugins.example")
.category(Category::Experimental)

View File

@ -3,13 +3,13 @@ use nu_protocol::{Category, PluginSignature, Value};
use crate::Example;
pub struct NuExampleDisableGc;
pub struct DisableGc;
impl SimplePluginCommand for NuExampleDisableGc {
impl SimplePluginCommand for DisableGc {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("nu-example-disable-gc")
PluginSignature::build("example disable-gc")
.usage("Disable the plugin garbage collector for `example`")
.extra_usage(
"\

View File

@ -3,13 +3,13 @@ use nu_protocol::{Category, PluginSignature, SyntaxShape, Type, Value};
use crate::Example;
pub struct NuExampleEnv;
pub struct Env;
impl SimplePluginCommand for NuExampleEnv {
impl SimplePluginCommand for Env {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("nu-example-env")
PluginSignature::build("example env")
.usage("Get environment variable(s)")
.extra_usage("Returns all environment variables if no name provided")
.category(Category::Experimental)

View File

@ -1,16 +1,16 @@
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, PluginCommand};
use nu_protocol::{Category, PipelineData, PluginExample, PluginSignature, SyntaxShape, Type};
use crate::StreamExample;
use crate::Example;
/// `<list> | stream_example for-each { |value| ... }`
/// `<list> | example for-each { |value| ... }`
pub struct ForEach;
impl PluginCommand for ForEach {
type Plugin = StreamExample;
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("stream_example for-each")
PluginSignature::build("example for-each")
.usage("Example execution of a closure with a stream")
.extra_usage("Prints each value the closure returns to stderr")
.input_output_type(Type::ListStream, Type::Nothing)
@ -20,7 +20,7 @@ impl PluginCommand for ForEach {
"The closure to run for each input value",
)
.plugin_examples(vec![PluginExample {
example: "ls | get name | stream_example for-each { |f| ^file $f }".into(),
example: "ls | get name | example for-each { |f| ^file $f }".into(),
description: "example with an external command".into(),
result: None,
}])
@ -29,7 +29,7 @@ impl PluginCommand for ForEach {
fn run(
&self,
_plugin: &StreamExample,
_plugin: &Example,
engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,

View File

@ -4,16 +4,16 @@ use nu_protocol::{
SyntaxShape, Type, Value,
};
use crate::StreamExample;
use crate::Example;
/// `stream_example generate <initial> { |previous| {out: ..., next: ...} }`
/// `example generate <initial> { |previous| {out: ..., next: ...} }`
pub struct Generate;
impl PluginCommand for Generate {
type Plugin = StreamExample;
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("stream_example generate")
PluginSignature::build("example generate")
.usage("Example execution of a closure to produce a stream")
.extra_usage("See the builtin `generate` command")
.input_output_type(Type::Nothing, Type::ListStream)
@ -28,8 +28,7 @@ impl PluginCommand for Generate {
"The closure to run to generate values",
)
.plugin_examples(vec![PluginExample {
example:
"stream_example generate 0 { |i| if $i <= 10 { {out: $i, next: ($i + 2)} } }"
example: "example generate 0 { |i| if $i <= 10 { {out: $i, next: ($i + 2)} } }"
.into(),
description: "Generate a sequence of numbers".into(),
result: Some(Value::test_list(
@ -44,7 +43,7 @@ impl PluginCommand for Generate {
fn run(
&self,
_plugin: &StreamExample,
_plugin: &Example,
engine: &EngineInterface,
call: &EvaluatedCall,
_input: PipelineData,

View File

@ -0,0 +1,41 @@
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
use nu_protocol::{Category, PluginSignature, Value};
use crate::Example;
pub struct Main;
impl SimplePluginCommand for Main {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("example")
.usage("Example commands for Nushell plugins")
.extra_usage(
r#"
The `example` plugin demonstrates usage of the Nushell plugin API.
Several commands provided to test and demonstrate different capabilities of
plugins exposed through the API. None of these commands are intended to be
particularly useful.
"#
.trim(),
)
.search_terms(vec!["example".into()])
.category(Category::Experimental)
}
fn run(
&self,
_plugin: &Self::Plugin,
_engine: &EngineInterface,
call: &EvaluatedCall,
_input: &Value,
) -> Result<Value, LabeledError> {
Err(LabeledError {
label: "No subcommand provided".into(),
msg: "add --help to see a list of subcommands".into(),
span: Some(call.head),
})
}
}

View File

@ -1,13 +1,35 @@
mod nu_example_1;
mod nu_example_2;
mod nu_example_3;
mod nu_example_config;
mod nu_example_disable_gc;
mod nu_example_env;
// `example` command - just suggests to call --help
mod main;
pub use nu_example_1::NuExample1;
pub use nu_example_2::NuExample2;
pub use nu_example_3::NuExample3;
pub use nu_example_config::NuExampleConfig;
pub use nu_example_disable_gc::NuExampleDisableGc;
pub use nu_example_env::NuExampleEnv;
pub use main::Main;
// Basic demos
mod one;
mod three;
mod two;
pub use one::One;
pub use three::Three;
pub use two::Two;
// Engine interface demos
mod config;
mod disable_gc;
mod env;
pub use config::Config;
pub use disable_gc::DisableGc;
pub use env::Env;
// Stream demos
mod collect_external;
mod for_each;
mod generate;
mod seq;
mod sum;
pub use collect_external::CollectExternal;
pub use for_each::ForEach;
pub use generate::Generate;
pub use seq::Seq;
pub use sum::Sum;

View File

@ -3,17 +3,17 @@ use nu_protocol::{Category, PluginExample, PluginSignature, SyntaxShape, Value};
use crate::Example;
pub struct NuExample1;
pub struct One;
impl SimplePluginCommand for NuExample1 {
impl SimplePluginCommand for One {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
// The signature defines the usage of the command inside Nu, and also automatically
// generates its help page.
PluginSignature::build("nu-example-1")
PluginSignature::build("example one")
.usage("PluginSignature test 1 for plugin. Returns Value::Nothing")
.extra_usage("Extra usage for nu-example-1")
.extra_usage("Extra usage for example one")
.search_terms(vec!["example".into()])
.required("a", SyntaxShape::Int, "required integer value")
.required("b", SyntaxShape::String, "required string value")
@ -22,7 +22,7 @@ impl SimplePluginCommand for NuExample1 {
.named("named", SyntaxShape::String, "named string", Some('n'))
.rest("rest", SyntaxShape::String, "rest value string")
.plugin_examples(vec![PluginExample {
example: "nu-example-1 3 bb".into(),
example: "example one 3 bb".into(),
description: "running example with an int value and string value".into(),
result: None,
}])

View File

@ -3,23 +3,23 @@ use nu_protocol::{
Category, ListStream, PipelineData, PluginExample, PluginSignature, SyntaxShape, Type, Value,
};
use crate::StreamExample;
use crate::Example;
/// `stream_example seq <first> <last>`
/// `example seq <first> <last>`
pub struct Seq;
impl PluginCommand for Seq {
type Plugin = StreamExample;
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("stream_example seq")
PluginSignature::build("example seq")
.usage("Example stream generator for a list of values")
.search_terms(vec!["example".into()])
.required("first", SyntaxShape::Int, "first number to generate")
.required("last", SyntaxShape::Int, "last number to generate")
.input_output_type(Type::Nothing, Type::List(Type::Int.into()))
.plugin_examples(vec![PluginExample {
example: "stream_example seq 1 3".into(),
example: "example seq 1 3".into(),
description: "generate a sequence from 1 to 3".into(),
result: Some(Value::test_list(vec![
Value::test_int(1),
@ -32,7 +32,7 @@ impl PluginCommand for Seq {
fn run(
&self,
_plugin: &StreamExample,
_plugin: &Example,
_engine: &EngineInterface,
call: &EvaluatedCall,
_input: PipelineData,

View File

@ -1,16 +1,16 @@
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, PluginCommand};
use nu_protocol::{Category, PipelineData, PluginExample, PluginSignature, Span, Type, Value};
use crate::StreamExample;
use crate::Example;
/// `<list> | stream_example sum`
/// `<list> | example sum`
pub struct Sum;
impl PluginCommand for Sum {
type Plugin = StreamExample;
type Plugin = Example;
fn signature(&self) -> PluginSignature {
PluginSignature::build("stream_example sum")
PluginSignature::build("example sum")
.usage("Example stream consumer for a list of values")
.search_terms(vec!["example".into()])
.input_output_types(vec![
@ -18,7 +18,7 @@ impl PluginCommand for Sum {
(Type::List(Type::Float.into()), Type::Float),
])
.plugin_examples(vec![PluginExample {
example: "seq 1 5 | stream_example sum".into(),
example: "seq 1 5 | example sum".into(),
description: "sum values from 1 to 5".into(),
result: Some(Value::test_int(15)),
}])
@ -27,7 +27,7 @@ impl PluginCommand for Sum {
fn run(
&self,
_plugin: &StreamExample,
_plugin: &Example,
_engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,

View File

@ -3,15 +3,15 @@ use nu_protocol::{Category, PluginSignature, SyntaxShape, Value};
use crate::Example;
pub struct NuExample3;
pub struct Three;
impl SimplePluginCommand for NuExample3 {
impl SimplePluginCommand for Three {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
// The signature defines the usage of the command inside Nu, and also automatically
// generates its help page.
PluginSignature::build("nu-example-3")
PluginSignature::build("example three")
.usage("PluginSignature test 3 for plugin. Returns labeled error")
.required("a", SyntaxShape::Int, "required integer value")
.required("b", SyntaxShape::String, "required string value")

View File

@ -3,15 +3,15 @@ use nu_protocol::{record, Category, PluginSignature, SyntaxShape, Value};
use crate::Example;
pub struct NuExample2;
pub struct Two;
impl SimplePluginCommand for NuExample2 {
impl SimplePluginCommand for Two {
type Plugin = Example;
fn signature(&self) -> PluginSignature {
// The signature defines the usage of the command inside Nu, and also automatically
// generates its help page.
PluginSignature::build("nu-example-2")
PluginSignature::build("example two")
.usage("PluginSignature test 2 for plugin. Returns list of records")
.required("a", SyntaxShape::Int, "required integer value")
.required("b", SyntaxShape::String, "required string value")

View File

@ -13,12 +13,21 @@ impl Plugin for Example {
//
// If it doesn't appear on this list, it won't be added.
vec![
Box::new(NuExample1),
Box::new(NuExample2),
Box::new(NuExample3),
Box::new(NuExampleConfig),
Box::new(NuExampleEnv),
Box::new(NuExampleDisableGc),
Box::new(Main),
// Basic demos
Box::new(One),
Box::new(Two),
Box::new(Three),
// Engine interface demos
Box::new(Config),
Box::new(Env),
Box::new(DisableGc),
// Stream demos
Box::new(CollectExternal),
Box::new(ForEach),
Box::new(Generate),
Box::new(Seq),
Box::new(Sum),
]
}
}

View File

@ -1,19 +0,0 @@
[package]
authors = ["The Nushell Project Developers"]
description = "An example of stream handling in nushell plugins"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu_plugin_stream_example"
edition = "2021"
license = "MIT"
name = "nu_plugin_stream_example"
version = "0.91.1"
[[bin]]
name = "nu_plugin_stream_example"
bench = false
[lib]
bench = false
[dependencies]
nu-plugin = { path = "../nu-plugin", version = "0.91.1" }
nu-protocol = { path = "../nu-protocol", version = "0.91.1", features = ["plugin"] }

View File

@ -1,62 +0,0 @@
# Streaming Plugin Example
Crate with a simple example of a plugin with commands that produce streams
## `stream_example seq`
This command demonstrates generating list streams. It generates numbers from the first argument
to the second argument just like the builtin `seq` command does.
Examples:
> ```nushell
> stream_example seq 1 10
> ```
[1 2 3 4 5 6 7 8 9 10]
> ```nushell
> stream_example seq 1 10 | describe
> ```
list<int> (stream)
## `stream_example sum`
This command demonstrates consuming list streams. It consumes a stream of numbers and calculates the
sum just like the builtin `math sum` command does.
Examples:
> ```nushell
> seq 1 5 | stream_example sum
> ```
15
## `stream_example collect-external`
This command demonstrates transforming streams into external streams. The list (or stream) of
strings on input will be concatenated into an external stream (raw input) on stdout.
> ```nushell
> [Hello "\n" world how are you] | stream_example collect-external
> ````
Hello
worldhowareyou
## `stream_example for-each`
This command demonstrates executing closures on values in streams. Each value received on the input
will be printed to the plugin's stderr. This works even with external commands.
> ```nushell
> ls | get name | stream_example for-each { |f| ^file $f }
> ```
CODE_OF_CONDUCT.md: ASCII text
CONTRIBUTING.md: ASCII text, with very long lines (303)
...

View File

@ -1,11 +0,0 @@
mod collect_external;
mod for_each;
mod generate;
mod seq;
mod sum;
pub use collect_external::CollectExternal;
pub use for_each::ForEach;
pub use generate::Generate;
pub use seq::Seq;
pub use sum::Sum;

View File

@ -1,50 +0,0 @@
use nu_plugin::{
EngineInterface, EvaluatedCall, LabeledError, Plugin, PluginCommand, SimplePluginCommand,
};
use nu_protocol::{Category, PluginSignature, Value};
mod commands;
pub use commands::*;
pub struct StreamExample;
impl Plugin for StreamExample {
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
vec![
Box::new(Main),
Box::new(Seq),
Box::new(Sum),
Box::new(CollectExternal),
Box::new(ForEach),
Box::new(Generate),
]
}
}
/// `stream_example`
pub struct Main;
impl SimplePluginCommand for Main {
type Plugin = StreamExample;
fn signature(&self) -> PluginSignature {
PluginSignature::build("stream_example")
.usage("Examples for streaming plugins")
.search_terms(vec!["example".into()])
.category(Category::Experimental)
}
fn run(
&self,
_plugin: &StreamExample,
_engine: &EngineInterface,
call: &EvaluatedCall,
_input: &Value,
) -> Result<Value, LabeledError> {
Err(LabeledError {
label: "No subcommand provided".into(),
msg: "add --help here to see usage".into(),
span: Some(call.head.past()),
})
}
}

View File

@ -1,30 +0,0 @@
use nu_plugin::{serve_plugin, MsgPackSerializer};
use nu_plugin_stream_example::StreamExample;
fn main() {
// When defining your plugin, you can select the Serializer that could be
// used to encode and decode the messages. The available options are
// MsgPackSerializer and JsonSerializer. Both are defined in the serializer
// folder in nu-plugin.
serve_plugin(&StreamExample {}, MsgPackSerializer {})
// Note
// When creating plugins in other languages one needs to consider how a plugin
// is added and used in nushell.
// The steps are:
// - The plugin is register. In this stage nushell calls the binary file of
// the plugin sending information using the encoded PluginCall::PluginSignature object.
// Use this encoded data in your plugin to design the logic that will return
// the encoded signatures.
// Nushell is expecting and encoded PluginResponse::PluginSignature with all the
// plugin signatures
// - When calling the plugin, nushell sends to the binary file the encoded
// PluginCall::CallInfo which has all the call information, such as the
// values of the arguments, the name of the signature called and the input
// from the pipeline.
// Use this data to design your plugin login and to create the value that
// will be sent to nushell
// Nushell expects an encoded PluginResponse::Value from the plugin
// - If an error needs to be sent back to nushell, one can encode PluginResponse::Error.
// This is a labeled error that nushell can format for pretty printing
}

View File

@ -101,12 +101,12 @@ fn plugin_commands_run_without_error() {
cwd: ".",
plugins: [
("nu_plugin_inc"),
("nu_plugin_stream_example"),
("nu_plugin_example"),
("nu_plugin_custom_values"),
],
r#"
"2.0.0" | inc -m | ignore
stream_example seq 1 10 | ignore
example seq 1 10 | ignore
custom-value generate | ignore
"#
);
@ -120,14 +120,14 @@ fn plugin_commands_run_multiple_times_without_error() {
cwd: ".",
plugins: [
("nu_plugin_inc"),
("nu_plugin_stream_example"),
("nu_plugin_example"),
("nu_plugin_custom_values"),
],
r#"
["2.0.0" "2.1.0" "2.2.0"] | each { inc -m } | print
stream_example seq 1 10 | ignore
example seq 1 10 | ignore
custom-value generate | ignore
stream_example seq 1 20 | ignore
example seq 1 20 | ignore
custom-value generate2 | ignore
"#
);
@ -340,9 +340,9 @@ fn plugin_gc_can_be_disabled_by_plugin() {
cwd: ".",
plugin: ("nu_plugin_example"),
r#"
nu-example-disable-gc
example disable-gc
$env.config.plugin_gc = { default: { stop_after: 0sec } }
nu-example-1 1 foo | ignore # ensure we've run the plugin with the new config
example one 1 foo | ignore # ensure we've run the plugin with the new config
sleep 100ms
(plugin list | where name == example).0.is_running
"#
@ -355,11 +355,11 @@ fn plugin_gc_can_be_disabled_by_plugin() {
fn plugin_gc_does_not_stop_plugin_while_stream_output_is_active() {
let out = nu_with_plugins!(
cwd: ".",
plugin: ("nu_plugin_stream_example"),
plugin: ("nu_plugin_example"),
r#"
$env.config.plugin_gc = { default: { stop_after: 10ms } }
# This would exceed the configured time
stream_example seq 1 500 | each { |n| sleep 1ms; $n } | length | print
example seq 1 500 | each { |n| sleep 1ms; $n } | length | print
"#
);
assert!(out.status.success());

View File

@ -15,7 +15,7 @@ fn closure() {
}
}
}
nu-example-config
example config
"#
);
@ -27,7 +27,7 @@ fn none() {
let actual = nu_with_plugins!(
cwd: "tests",
plugin: ("nu_plugin_example"),
"nu-example-config"
"example config"
);
assert!(actual.err.contains("No config sent"));
@ -47,7 +47,7 @@ fn record() {
}
}
}
nu-example-config
example config
"#
);

View File

@ -7,9 +7,9 @@ fn get_env_by_name() {
plugin: ("nu_plugin_example"),
r#"
$env.FOO = bar
nu-example-env FOO | print
example env FOO | print
$env.FOO = baz
nu-example-env FOO | print
example env FOO | print
"#
);
assert!(result.status.success());
@ -21,7 +21,7 @@ fn get_envs() {
let result = nu_with_plugins!(
cwd: ".",
plugin: ("nu_plugin_example"),
"$env.BAZ = foo; nu-example-env | get BAZ"
"$env.BAZ = foo; example env | get BAZ"
);
assert!(result.status.success());
assert_eq!("foo", result.out);
@ -37,7 +37,7 @@ fn get_current_dir() {
let result = nu_with_plugins!(
cwd: ".",
plugin: ("nu_plugin_example"),
"cd tests; nu-example-env --cwd"
"cd tests; example env --cwd"
);
assert!(result.status.success());
assert_eq!(cwd, result.out);
@ -48,7 +48,7 @@ fn set_env() {
let result = nu_with_plugins!(
cwd: ".",
plugin: ("nu_plugin_example"),
"nu-example-env NUSHELL_OPINION --set=rocks; $env.NUSHELL_OPINION"
"example env NUSHELL_OPINION --set=rocks; $env.NUSHELL_OPINION"
);
assert!(result.status.success());
assert_eq!("rocks", result.out);

View File

@ -7,11 +7,11 @@ fn help() {
let actual = nu_with_plugins!(
cwd: dirs.test(),
plugin: ("nu_plugin_example"),
"nu-example-1 --help"
"example one --help"
);
assert!(actual.out.contains("PluginSignature test 1"));
assert!(actual.out.contains("Extra usage for nu-example-1"));
assert!(actual.out.contains("Extra usage for example one"));
})
}
@ -21,7 +21,7 @@ fn search_terms() {
let actual = nu_with_plugins!(
cwd: dirs.test(),
plugin: ("nu_plugin_example"),
r#"help commands | where name == "nu-example-1" | echo $"search terms: ($in.search_terms)""#
r#"help commands | where name == "example one" | echo $"search terms: ($in.search_terms)""#
);
assert!(actual.out.contains("search terms: [example]"));

View File

@ -5,8 +5,8 @@ use pretty_assertions::assert_eq;
fn seq_produces_stream() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"stream_example seq 1 5 | describe"
plugin: ("nu_plugin_example"),
"example seq 1 5 | describe"
);
assert_eq!(actual.out, "list<int> (stream)");
@ -20,8 +20,8 @@ fn seq_describe_no_collect_succeeds_without_error() {
for _ in 0..10 {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"stream_example seq 1 5 | describe --no-collect"
plugin: ("nu_plugin_example"),
"example seq 1 5 | describe --no-collect"
);
assert_eq!(actual.out, "stream");
@ -33,16 +33,16 @@ fn seq_describe_no_collect_succeeds_without_error() {
fn seq_stream_collects_to_correct_list() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"stream_example seq 1 5 | to json --raw"
plugin: ("nu_plugin_example"),
"example seq 1 5 | to json --raw"
);
assert_eq!(actual.out, "[1,2,3,4,5]");
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"stream_example seq 1 0 | to json --raw"
plugin: ("nu_plugin_example"),
"example seq 1 0 | to json --raw"
);
assert_eq!(actual.out, "[]");
@ -53,8 +53,8 @@ fn seq_big_stream() {
// Testing big streams helps to ensure there are no deadlocking bugs
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"stream_example seq 1 100000 | length"
plugin: ("nu_plugin_example"),
"example seq 1 100000 | length"
);
assert_eq!(actual.out, "100000");
@ -64,8 +64,8 @@ fn seq_big_stream() {
fn sum_accepts_list_of_int() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"[1 2 3] | stream_example sum"
plugin: ("nu_plugin_example"),
"[1 2 3] | example sum"
);
assert_eq!(actual.out, "6");
@ -75,8 +75,8 @@ fn sum_accepts_list_of_int() {
fn sum_accepts_list_of_float() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"[1.0 2.0 3.5] | stream_example sum"
plugin: ("nu_plugin_example"),
"[1.0 2.0 3.5] | example sum"
);
assert_eq!(actual.out, "6.5");
@ -86,8 +86,8 @@ fn sum_accepts_list_of_float() {
fn sum_accepts_stream_of_int() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"seq 1 5 | stream_example sum"
plugin: ("nu_plugin_example"),
"seq 1 5 | example sum"
);
assert_eq!(actual.out, "15");
@ -97,8 +97,8 @@ fn sum_accepts_stream_of_int() {
fn sum_accepts_stream_of_float() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"seq 1 5 | into float | stream_example sum"
plugin: ("nu_plugin_example"),
"seq 1 5 | into float | example sum"
);
assert_eq!(actual.out, "15");
@ -109,8 +109,8 @@ fn sum_big_stream() {
// Testing big streams helps to ensure there are no deadlocking bugs
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"seq 1 100000 | stream_example sum"
plugin: ("nu_plugin_example"),
"seq 1 100000 | example sum"
);
assert_eq!(actual.out, "5000050000");
@ -120,8 +120,8 @@ fn sum_big_stream() {
fn collect_external_accepts_list_of_string() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"[a b] | stream_example collect-external"
plugin: ("nu_plugin_example"),
"[a b] | example collect-external"
);
assert_eq!(actual.out, "ab");
@ -131,8 +131,8 @@ fn collect_external_accepts_list_of_string() {
fn collect_external_accepts_list_of_binary() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"[0x[41] 0x[42]] | stream_example collect-external"
plugin: ("nu_plugin_example"),
"[0x[41] 0x[42]] | example collect-external"
);
assert_eq!(actual.out, "AB");
@ -142,8 +142,8 @@ fn collect_external_accepts_list_of_binary() {
fn collect_external_produces_raw_input() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"[a b c] | stream_example collect-external | describe"
plugin: ("nu_plugin_example"),
"[a b c] | example collect-external | describe"
);
assert_eq!(actual.out, "raw input");
@ -155,12 +155,12 @@ fn collect_external_big_stream() {
// time without deadlocking
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
plugin: ("nu_plugin_example"),
r#"(
seq 1 10000 |
to text |
each { into string } |
stream_example collect-external |
example collect-external |
lines |
length
)"#
@ -173,8 +173,8 @@ fn collect_external_big_stream() {
fn for_each_prints_on_stderr() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"[a b c] | stream_example for-each { $in }"
plugin: ("nu_plugin_example"),
"[a b c] | example for-each { $in }"
);
assert_eq!(actual.err, "a\nb\nc\n");
@ -184,8 +184,8 @@ fn for_each_prints_on_stderr() {
fn generate_sequence() {
let actual = nu_with_plugins!(
cwd: "tests/fixtures/formats",
plugin: ("nu_plugin_stream_example"),
"stream_example generate 0 { |i| if $i <= 10 { {out: $i, next: ($i + 2)} } } | to json --raw"
plugin: ("nu_plugin_example"),
"example generate 0 { |i| if $i <= 10 { {out: $i, next: ($i + 2)} } } | to json --raw"
);
assert_eq!(actual.out, "[0,2,4,6,8,10]");

View File

@ -281,6 +281,7 @@
Source='target\$(var.Profile)\nu_plugin_gstat.exe'
KeyPath='yes'/>
</Component>
<!--
<Component Id='binary23' Guid='*' Win64='$(var.Win64)'>
<File
Id='exe23'
@ -289,6 +290,7 @@
Source='target\$(var.Profile)\nu_plugin_stream_example.exe'
KeyPath='yes'/>
</Component>
-->
</Directory>
</Directory>
</Directory>
@ -353,7 +355,7 @@
<ComponentRef Id='binary20'/>
<ComponentRef Id='binary21'/> -->
<ComponentRef Id='binary22'/>
<ComponentRef Id='binary23'/>
<!-- <ComponentRef Id='binary23'/> -->
<Feature
Id='Environment'