mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 06:20:23 +02:00
WIP - more streamlining
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use crate::commands::{RawCommandArgs, StaticCommand};
|
||||
use crate::context::{SourceMap, SpanSource};
|
||||
use crate::errors::ShellError;
|
||||
use crate::format::GenericView;
|
||||
use crate::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -33,7 +32,7 @@ pub fn autoview(
|
||||
mut context: RunnableContext,
|
||||
raw: RawCommandArgs,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let stream = async_stream_block! {
|
||||
Ok(OutputStream::new(async_stream_block! {
|
||||
let input = context.input.drain_vec().await;
|
||||
|
||||
if input.len() > 0 {
|
||||
@@ -60,9 +59,7 @@ pub fn autoview(
|
||||
// }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(OutputStream::new(stream))
|
||||
}))
|
||||
}
|
||||
|
||||
fn equal_shapes(input: &Vec<Spanned<Value>>) -> bool {
|
||||
|
@@ -35,7 +35,7 @@ pub fn clip(
|
||||
let stream = async_stream_block! {
|
||||
let values: Vec<Spanned<Value>> = input.values.collect().await;
|
||||
|
||||
inner_clip(values, name);
|
||||
inner_clip(values, name).await;
|
||||
};
|
||||
|
||||
let stream: BoxStream<'static, ReturnValue> = stream.boxed();
|
||||
|
@@ -159,18 +159,6 @@ impl CommandArgs {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SinkContext {
|
||||
pub input: Vec<Spanned<Value>>,
|
||||
pub env: Arc<Mutex<Environment>>,
|
||||
pub name: Option<Span>,
|
||||
}
|
||||
|
||||
pub struct SinkArgs<T> {
|
||||
args: T,
|
||||
context: SinkContext,
|
||||
callback: fn(T, SinkContext) -> Result<(), ShellError>,
|
||||
}
|
||||
|
||||
pub struct RunnableContext {
|
||||
pub input: InputStream,
|
||||
pub env: Arc<Mutex<Environment>>,
|
||||
@@ -412,12 +400,6 @@ impl Command {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_sink(&self) -> bool {
|
||||
match self {
|
||||
Command::Static(..) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn signature(&self) -> Signature {
|
||||
match self {
|
||||
Command::Static(command) => command.signature(),
|
||||
|
@@ -3,7 +3,6 @@ use crate::errors::ShellError;
|
||||
use crate::parser::registry;
|
||||
use crate::prelude::*;
|
||||
use derive_new::new;
|
||||
use futures_async_stream::async_stream_block;
|
||||
use serde::{self, Deserialize, Serialize};
|
||||
use std::io::prelude::*;
|
||||
use std::io::BufReader;
|
||||
@@ -60,38 +59,6 @@ impl StaticCommand for PluginCommand {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(new)]
|
||||
pub struct PluginSink {
|
||||
path: String,
|
||||
config: registry::Signature,
|
||||
}
|
||||
|
||||
impl StaticCommand for PluginSink {
|
||||
fn run(
|
||||
&self,
|
||||
args: CommandArgs,
|
||||
registry: &CommandRegistry,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let path = self.path.clone();
|
||||
|
||||
let stream = async_stream_block! {
|
||||
sink_plugin(path, args).await;
|
||||
};
|
||||
|
||||
let stream: BoxStream<'static, ReturnValue> = stream.boxed();
|
||||
|
||||
Ok(OutputStream::from(stream))
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
&self.config.name
|
||||
}
|
||||
|
||||
fn signature(&self) -> registry::Signature {
|
||||
self.config.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filter_plugin(
|
||||
path: String,
|
||||
args: CommandArgs,
|
||||
@@ -207,22 +174,3 @@ pub fn filter_plugin(
|
||||
|
||||
Ok(stream.to_output_stream())
|
||||
}
|
||||
|
||||
pub async fn sink_plugin(path: String, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
//use subprocess::Exec;
|
||||
let input: Vec<Spanned<Value>> = args.input.values.collect().await;
|
||||
let request = JsonRpc::new("sink", (args.call_info, input));
|
||||
let request_raw = serde_json::to_string(&request).unwrap();
|
||||
let mut tmpfile = tempfile::NamedTempFile::new()?;
|
||||
let _ = writeln!(tmpfile, "{}", request_raw);
|
||||
let _ = tmpfile.flush();
|
||||
|
||||
let mut child = std::process::Command::new(path)
|
||||
.arg(tmpfile.path())
|
||||
.spawn()
|
||||
.expect("Failed to spawn child process");
|
||||
|
||||
let _ = child.wait();
|
||||
|
||||
Ok(OutputStream::empty())
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
use crate::commands::{EvaluatedStaticCommandArgs, StaticCommand};
|
||||
use crate::commands::StaticCommand;
|
||||
use crate::errors::ShellError;
|
||||
use crate::parser::hir::SyntaxType;
|
||||
use crate::parser::registry::{NamedType, PositionalType};
|
||||
use crate::prelude::*;
|
||||
use indexmap::IndexMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct Remove;
|
||||
|
@@ -4,10 +4,10 @@ use crate::commands::to_toml::value_to_toml_value;
|
||||
use crate::commands::to_yaml::value_to_yaml_value;
|
||||
use crate::commands::StaticCommand;
|
||||
use crate::errors::ShellError;
|
||||
use crate::object::{Primitive, Value};
|
||||
use crate::object::Value;
|
||||
use crate::parser::Spanned;
|
||||
use crate::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct Save;
|
||||
|
||||
|
@@ -24,7 +24,7 @@ impl StaticCommand for VTable {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vtable(args: VTableArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
|
||||
pub fn vtable(_args: VTableArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
|
||||
let stream = async_stream_block! {
|
||||
let input = context.input.into_vec().await;
|
||||
|
||||
|
Reference in New Issue
Block a user