Batch of dataframe commands (#442)

* corrected missing shellerror type

* batch dataframe commands

* removed option to find declaration with input

* ordered dataframe folders
This commit is contained in:
Fernando Herrera
2021-12-06 04:09:49 +00:00
committed by GitHub
parent fdde95f675
commit 1fd26727c5
22 changed files with 471 additions and 127 deletions

View File

@ -1,7 +1,7 @@
use super::Command;
use crate::{
ast::Block, BlockId, DeclId, Example, Overlay, OverlayId, PipelineData, ShellError, Signature,
Span, Type, Value, VarId,
ast::Block, BlockId, DeclId, Example, Overlay, OverlayId, ShellError, Signature, Span, Type,
VarId,
};
use core::panic;
use std::{
@ -370,39 +370,6 @@ impl EngineState {
.expect("internal error: missing declaration")
}
#[allow(clippy::borrowed_box)]
pub fn get_decl_with_input(&self, decl_id: DeclId, input: &PipelineData) -> &Box<dyn Command> {
let decl = self.get_decl(decl_id);
match input {
PipelineData::Stream(..) => decl,
PipelineData::Value(value, ..) => match value {
Value::CustomValue { val, .. } => {
// This filter works because the custom definitions were declared
// before the default nushell declarations. This means that the custom
// declarations that get overridden by the default declarations can only
// be accessed if the input value has the required category
let decls = self
.decls
.iter()
.enumerate()
.filter(|(_, decl_inner)| {
decl.name() == decl_inner.name()
&& decl_inner.signature().category == val.category()
})
.map(|(index, _)| index)
.collect::<Vec<usize>>();
match decls.first() {
Some(index) => self.get_decl(*index),
None => decl,
}
}
_ => decl,
},
}
}
/// Get all IDs of all commands within scope, sorted by the commads' names
pub fn get_decl_ids_sorted(&self, include_hidden: bool) -> impl Iterator<Item = DeclId> {
let mut decls_map = HashMap::new();

View File

@ -30,7 +30,9 @@ pub trait CustomValue: fmt::Debug + Send + Sync {
fn follow_path_string(&self, column_name: String, span: Span) -> Result<Value, ShellError>;
// ordering with other value
fn partial_cmp(&self, other: &Value) -> Option<Ordering>;
fn partial_cmp(&self, _other: &Value) -> Option<Ordering> {
None
}
// Definition of an operation between the object that implements the trait
// and another Value.