mirror of
https://github.com/nushell/nushell.git
synced 2025-03-30 10:37:29 +02:00
headers plugin
This commit is contained in:
parent
06f87cfbe8
commit
509a856679
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -2500,6 +2500,16 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nu_plugin_headers"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"nu-errors",
|
||||||
|
"nu-plugin",
|
||||||
|
"nu-protocol",
|
||||||
|
"nu-source",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu_plugin_inc"
|
name = "nu_plugin_inc"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
39
crates/nu-cli/src/commands/headers.rs
Normal file
39
crates/nu-cli/src/commands/headers.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
use crate::commands::WholeStreamCommand;
|
||||||
|
use crate::context::CommandRegistry;
|
||||||
|
use crate::prelude::*;
|
||||||
|
use futures::stream::StreamExt;
|
||||||
|
use nu_errors::ShellError;
|
||||||
|
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue, Value};
|
||||||
|
|
||||||
|
pub struct Headers;
|
||||||
|
|
||||||
|
impl WholeStreamCommand for Headers {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"headers"
|
||||||
|
}
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("headers")
|
||||||
|
}
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Use the first row of the table as headers"
|
||||||
|
}
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
args: CommandArgs,
|
||||||
|
registry: &CommandRegistry,
|
||||||
|
) -> Result<OutputStream, ShellError> {
|
||||||
|
args.process(registry, count)?.run()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn count(
|
||||||
|
CountArgs {}: CountArgs,
|
||||||
|
RunnableContext { input, name, .. }: RunnableContext,
|
||||||
|
) -> Result<OutputStream, ShellError> {
|
||||||
|
let stream = async_stream! {
|
||||||
|
let rows: Vec<Value> = input.values.collect().await;
|
||||||
|
|
||||||
|
yield ReturnSuccess::value(UntaggedValue::int(rows.len()).into_value(name))
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(stream.to_output_stream())
|
||||||
|
}
|
0
crates/nu_plugin_headers/.projectile
Normal file
0
crates/nu_plugin_headers/.projectile
Normal file
13
crates/nu_plugin_headers/Cargo.toml
Normal file
13
crates/nu_plugin_headers/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "nu_plugin_headers"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Sam Hedin <sam.hedin@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nu-plugin = { path = "../nu-plugin", version = "0.11.0" }
|
||||||
|
nu-protocol = { path = "../nu-protocol", version = "0.11.0" }
|
||||||
|
nu-source = { path = "../nu-source", version = "0.11.0" }
|
||||||
|
nu-errors = { path = "../nu-errors", version = "0.11.0" }
|
2
crates/nu_plugin_headers/Makefile
Normal file
2
crates/nu_plugin_headers/Makefile
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
out:
|
||||||
|
cargo install --path . --force
|
18
crates/nu_plugin_headers/src/headers.rs
Normal file
18
crates/nu_plugin_headers/src/headers.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
pub struct Headers;
|
||||||
|
impl Headers {
|
||||||
|
pub fn new() -> Headers {
|
||||||
|
Headers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WholeStreamCommand for Headers {
|
||||||
|
fn name(&self) -> &str{
|
||||||
|
"headers"
|
||||||
|
}
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("headers")
|
||||||
|
}
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Use the first row of the table as headers"
|
||||||
|
}
|
||||||
|
}
|
3
crates/nu_plugin_headers/src/lib.rs
Normal file
3
crates/nu_plugin_headers/src/lib.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
mod nu;
|
||||||
|
mod headers;
|
||||||
|
pub use headers::Headers;
|
7
crates/nu_plugin_headers/src/main.rs
Normal file
7
crates/nu_plugin_headers/src/main.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use nu_plugin::serve_plugin;
|
||||||
|
use nu_plugin_headers::Headers;
|
||||||
|
|
||||||
|
//https://github.com/nushell/nushell/issues/1486
|
||||||
|
fn main() {
|
||||||
|
serve_plugin(&mut Headers::new())
|
||||||
|
}
|
16
crates/nu_plugin_headers/src/nu/mod.rs
Normal file
16
crates/nu_plugin_headers/src/nu/mod.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use crate::headers::Headers;
|
||||||
|
use nu_errors::ShellError;
|
||||||
|
use nu_plugin::Plugin;
|
||||||
|
use nu_protocol::{CallInfo, ReturnSuccess, ReturnValue, Signature, Value};
|
||||||
|
|
||||||
|
impl Plugin for Headers {
|
||||||
|
fn config(&mut self) -> Result<Signature, ShellError> {
|
||||||
|
Ok(Signature::build("headers")
|
||||||
|
.desc("Use the first row of the table as headers")
|
||||||
|
.filter())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn begin_filter(&mut self, call_info: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
|
||||||
|
Ok(vec![])
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user