WIP - more streamlining

This commit is contained in:
Yehuda Katz 2019-08-06 09:26:33 -07:00
parent 586aa6bae1
commit 14a52bc282
16 changed files with 23 additions and 116 deletions

View File

@ -479,7 +479,7 @@ fn classify_command(
}))
}
false => match context.get_command(name).as_ref() {
Command::Static(command) => {
Command::Static(_command) => {
let arg_list_strings: Vec<Spanned<String>> = match call.children() {
//Some(args) => args.iter().map(|i| i.as_external_arg(source)).collect(),
Some(args) => args

View File

@ -46,8 +46,8 @@ crate use autoview::Autoview;
crate use cd::Cd;
crate use clip::Clip;
crate use command::{
command, static_command, CallInfo, Command, CommandArgs, EvaluatedStaticCommandArgs,
RawCommandArgs, StaticCommand, UnevaluatedCallInfo,
command, static_command, Command, CommandArgs, RawCommandArgs, StaticCommand,
UnevaluatedCallInfo,
};
crate use config::Config;
crate use get::Get;

View File

@ -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 {

View File

@ -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();

View File

@ -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(),

View File

@ -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())
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,5 +1,5 @@
use crate::commands::{CallInfo, Command, StaticCommand, UnevaluatedCallInfo};
use crate::parser::{hir, registry, Span};
use crate::commands::{Command, UnevaluatedCallInfo};
use crate::parser::{hir, Span};
use crate::prelude::*;
use derive_new::new;

View File

@ -7,6 +7,7 @@ crate mod vtable;
use crate::prelude::*;
crate use entries::EntriesView;
#[allow(unused)]
crate use generic::GenericView;
crate use table::TableView;
crate use vtable::VTableView;

View File

@ -6,6 +6,7 @@ crate mod into;
crate mod process;
crate mod types;
#[allow(unused)]
crate use base::{Block, Primitive, Switch, Value};
crate use dict::{Dictionary, SpannedDictBuilder};
crate use files::dir_entry_dict;

View File

@ -492,16 +492,6 @@ impl Value {
}
}
crate fn as_pair(&self) -> Result<(Spanned<Value>, Spanned<Value>), ShellError> {
match self {
Value::List(list) if list.len() == 2 => Ok((list[0].clone(), list[1].clone())),
other => Err(ShellError::string(format!(
"Expected pair, got {:?}",
other
))),
}
}
crate fn as_string(&self) -> Result<String, ShellError> {
match self {
Value::Primitive(Primitive::String(s)) => Ok(s.clone()),
@ -529,17 +519,6 @@ impl Value {
}
}
crate fn as_block(&self) -> Result<Block, ShellError> {
match self {
Value::Block(block) => Ok(block.clone()),
// TODO: this should definitely be more general with better errors
other => Err(ShellError::string(format!(
"Expected block, got {:?}",
other
))),
}
}
crate fn is_true(&self) -> bool {
match self {
Value::Primitive(Primitive::Boolean(true)) => true,

View File

@ -14,7 +14,7 @@ pub trait ExtractType: Sized {
impl<T> ExtractType for T {
default fn extract(_value: &Spanned<Value>) -> Result<T, ShellError> {
let name = unsafe { std::intrinsics::type_name::<T>() };
let name = std::intrinsics::type_name::<T>();
Err(ShellError::unimplemented(format!(
"<T> ExtractType for {}",
name
@ -32,7 +32,7 @@ impl<T> ExtractType for T {
impl<T: ExtractType> ExtractType for Vec<Spanned<T>> {
fn extract(value: &Spanned<Value>) -> Result<Self, ShellError> {
let name = unsafe { std::intrinsics::type_name::<T>() };
let name = std::intrinsics::type_name::<T>();
trace!("<Vec> Extracting {:?} for Vec<{}>", value, name);
match value.item() {
@ -69,8 +69,8 @@ impl<T: ExtractType> ExtractType for Vec<Spanned<T>> {
impl<T: ExtractType, U: ExtractType> ExtractType for (T, U) {
fn extract(value: &Spanned<Value>) -> Result<(T, U), ShellError> {
let t_name = unsafe { std::intrinsics::type_name::<T>() };
let u_name = unsafe { std::intrinsics::type_name::<U>() };
let t_name = std::intrinsics::type_name::<T>();
let u_name = std::intrinsics::type_name::<U>();
trace!("Extracting {:?} for ({}, {})", value, t_name, u_name);
@ -98,7 +98,7 @@ impl<T: ExtractType, U: ExtractType> ExtractType for (T, U) {
impl<T: ExtractType> ExtractType for Option<T> {
fn extract(value: &Spanned<Value>) -> Result<Option<T>, ShellError> {
let name = unsafe { std::intrinsics::type_name::<T>() };
let name = std::intrinsics::type_name::<T>();
trace!("<Option> Extracting {:?} for Option<{}>", value, name);
let result = match value.item() {
@ -123,7 +123,7 @@ impl<T: ExtractType> ExtractType for Option<T> {
impl<T: ExtractType> ExtractType for Spanned<T> {
fn extract(value: &Spanned<Value>) -> Result<Spanned<T>, ShellError> {
let name = unsafe { std::intrinsics::type_name::<T>() };
let name = std::intrinsics::type_name::<T>();
trace!("<Spanned> Extracting {:?} for Spanned<{}>", value, name);
Ok(T::extract(value)?.spanned(value.span))

View File

@ -69,7 +69,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
V: Visitor<'de>,
{
let value = self.pop();
let name = unsafe { std::intrinsics::type_name::<V::Value>() };
let name = std::intrinsics::type_name::<V::Value>();
trace!("<Deserialize any> Extracting {:?}", name);
V::Value::extract(&value.val)
@ -236,7 +236,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
if self.saw_root {
let value = self.pop();
let name = unsafe { std::intrinsics::type_name::<V::Value>() };
let name = std::intrinsics::type_name::<V::Value>();
trace!("Extracting {:?} for {:?}", value.val, name);
V::Value::extract(&value.val)
} else {

View File

@ -51,6 +51,7 @@ crate use crate::Text;
crate use futures::stream::BoxStream;
crate use futures::{FutureExt, Stream, StreamExt};
crate use futures_async_stream::async_stream_block;
#[allow(unused)]
crate use serde::{Deserialize, Serialize};
crate use std::collections::VecDeque;
crate use std::future::Future;