Merge remote-tracking branch 'upstream/master' into initial-docker-command-impl

This commit is contained in:
Jonathan Rothberg
2019-09-23 17:57:56 -07:00
12 changed files with 344 additions and 74 deletions

View File

@ -72,25 +72,30 @@ fn load_plugin(path: &std::path::Path, context: &mut Context) -> Result<(), Shel
trace!("processing {:?}", params);
if params.is_filter {
let fname = fname.to_string();
let name = params.name.clone();
context.add_commands(vec![whole_stream_command(PluginCommand::new(
name, fname, params,
))]);
Ok(())
let name = params.name.clone();
let fname = fname.to_string();
if context.has_command(&name) {
trace!("plugin {:?} already loaded.", &name);
} else {
let fname = fname.to_string();
let name = params.name.clone();
context.add_commands(vec![whole_stream_command(PluginSink::new(
name, fname, params,
))]);
Ok(())
if params.is_filter {
context.add_commands(vec![whole_stream_command(
PluginCommand::new(name, fname, params),
)]);
} else {
context.add_commands(vec![whole_stream_command(PluginSink::new(
name, fname, params,
))]);
};
}
Ok(())
}
Err(e) => Err(e),
},
Err(e) => Err(ShellError::string(format!("Error: {:?}", e))),
Err(e) => {
trace!("incompatible plugin {:?}", input);
Err(ShellError::string(format!("Error: {:?}", e)))
}
}
}
Err(e) => Err(ShellError::string(format!("Error: {:?}", e))),
@ -202,7 +207,9 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> {
if is_valid_name && is_executable {
trace!("Trying {:?}", bin.display());
load_plugin(&bin, context)?;
// we are ok if this plugin load fails
let _ = load_plugin(&bin, context);
}
}
}

View File

@ -12,20 +12,6 @@ pub enum Description {
Synthetic(String),
}
impl Description {
pub fn from(value: Tagged<impl Into<String>>) -> Description {
let value_tag = value.tag();
match value_tag {
Tag {
span: crate::data::meta::Span { start: 0, end: 0 },
..
} => Description::Synthetic(value.item.into()),
_ => Description::Source(Tagged::from_item(value.item.into(), value_tag)),
}
}
}
impl Description {
fn into_label(self) -> Result<Label<Tag>, String> {
match self {
@ -114,10 +100,6 @@ impl ShellError {
.start()
}
pub(crate) fn missing_property(subpath: Description, expr: Description) -> ShellError {
ProximateShellError::MissingProperty { subpath, expr }.start()
}
pub(crate) fn missing_value(tag: Option<Tag>, reason: impl Into<String>) -> ShellError {
ProximateShellError::MissingValue {
tag,

View File

@ -1,5 +1,5 @@
use crate::data::base::Block;
use crate::errors::{ArgumentError, Description};
use crate::errors::ArgumentError;
use crate::parser::{
hir::{self, Expression, RawExpression},
CommandRegistry, Text,
@ -87,10 +87,20 @@ pub(crate) fn evaluate_baseline_expr(
match next {
None => {
return Err(ShellError::missing_property(
Description::from(item.tagged_type_name()),
Description::from(name.clone()),
))
let possibilities = item.data_descriptors();
let mut possible_matches: Vec<_> = possibilities
.iter()
.map(|x| (natural::distance::levenshtein_distance(x, &name), x))
.collect();
possible_matches.sort();
return Err(ShellError::labeled_error(
"Unknown column",
format!("did you mean '{}'?", possible_matches[0].1),
expr.tag(),
));
}
Some(next) => {
item = next.clone().item.tagged(expr.tag());