forked from extern/nushell
WIP
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -92,23 +92,21 @@ fn into_binary(
|
||||
let head = call.head;
|
||||
// let column_paths: Vec<CellPath> = call.rest(context, 0)?;
|
||||
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
action(v, head)
|
||||
// FIXME: Add back in cell_path support
|
||||
// if column_paths.is_empty() {
|
||||
// action(v, head)
|
||||
// } else {
|
||||
// let mut ret = v;
|
||||
// for path in &column_paths {
|
||||
// ret =
|
||||
// ret.swap_data_by_cell_path(path, Box::new(move |old| action(old, old.tag())))?;
|
||||
// }
|
||||
input.map(move |v| {
|
||||
action(v, head)
|
||||
// FIXME: Add back in cell_path support
|
||||
// if column_paths.is_empty() {
|
||||
// action(v, head)
|
||||
// } else {
|
||||
// let mut ret = v;
|
||||
// for path in &column_paths {
|
||||
// ret =
|
||||
// ret.swap_data_by_cell_path(path, Box::new(move |old| action(old, old.tag())))?;
|
||||
// }
|
||||
|
||||
// Ok(ret)
|
||||
// }
|
||||
})
|
||||
.into_pipeline_data())
|
||||
// Ok(ret)
|
||||
// }
|
||||
})
|
||||
}
|
||||
|
||||
fn int_to_endian(n: i64) -> Vec<u8> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -120,26 +120,24 @@ fn into_filesize(
|
||||
let head = call.head;
|
||||
// let call_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
action(v, head)
|
||||
input.map(move |v| {
|
||||
action(v, head)
|
||||
|
||||
// FIXME: Add back cell_path support
|
||||
// if column_paths.is_empty() {
|
||||
// action(&v, v.tag())
|
||||
// } else {
|
||||
// let mut ret = v;
|
||||
// for path in &column_paths {
|
||||
// ret = ret.swap_data_by_column_path(
|
||||
// path,
|
||||
// Box::new(move |old| action(old, old.tag())),
|
||||
// )?;
|
||||
// }
|
||||
// FIXME: Add back cell_path support
|
||||
// if column_paths.is_empty() {
|
||||
// action(&v, v.tag())
|
||||
// } else {
|
||||
// let mut ret = v;
|
||||
// for path in &column_paths {
|
||||
// ret = ret.swap_data_by_column_path(
|
||||
// path,
|
||||
// Box::new(move |old| action(old, old.tag())),
|
||||
// )?;
|
||||
// }
|
||||
|
||||
// Ok(ret)
|
||||
// }
|
||||
})
|
||||
.into_pipeline_data())
|
||||
// Ok(ret)
|
||||
// }
|
||||
})
|
||||
}
|
||||
|
||||
pub fn action(input: Value, span: Span) -> Value {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -96,23 +96,21 @@ fn into_int(
|
||||
let head = call.head;
|
||||
// let column_paths: Vec<CellPath> = call.rest(context, 0)?;
|
||||
|
||||
Ok(input
|
||||
.map(move |v| {
|
||||
action(v, head)
|
||||
// FIXME: Add back cell_path support
|
||||
// if column_paths.is_empty() {
|
||||
// action(&v, v.tag())
|
||||
// } else {
|
||||
// let mut ret = v;
|
||||
// for path in &column_paths {
|
||||
// ret = ret
|
||||
// .swap_data_by_column_path(path, Box::new(move |old| action(old, old.tag())))?;
|
||||
// }
|
||||
input.map(move |v| {
|
||||
action(v, head)
|
||||
// FIXME: Add back cell_path support
|
||||
// if column_paths.is_empty() {
|
||||
// action(&v, v.tag())
|
||||
// } else {
|
||||
// let mut ret = v;
|
||||
// for path in &column_paths {
|
||||
// ret = ret
|
||||
// .swap_data_by_column_path(path, Box::new(move |old| action(old, old.tag())))?;
|
||||
// }
|
||||
|
||||
// Ok(ret)
|
||||
// }
|
||||
})
|
||||
.into_pipeline_data())
|
||||
// Ok(ret)
|
||||
// }
|
||||
})
|
||||
}
|
||||
|
||||
pub fn action(input: Value, span: Span) -> Value {
|
||||
|
@ -60,7 +60,7 @@ impl Command for For {
|
||||
let mut stack = stack.collect_captures(&block.captures);
|
||||
|
||||
match values {
|
||||
Value::List { vals, span } => Ok(vals
|
||||
Value::List { vals, .. } => Ok(vals
|
||||
.into_iter()
|
||||
.map(move |x| {
|
||||
let mut stack = stack.clone();
|
||||
@ -68,25 +68,19 @@ impl Command for For {
|
||||
|
||||
let block = engine_state.get_block(block_id);
|
||||
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
|
||||
Ok(value) => Value::List {
|
||||
vals: value.collect(),
|
||||
span,
|
||||
},
|
||||
Ok(pipeline_data) => pipeline_data.into_value(),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
})
|
||||
.into_pipeline_data()),
|
||||
Value::Range { val, span } => Ok(val
|
||||
Value::Range { val, .. } => Ok(val
|
||||
.into_range_iter()?
|
||||
.map(move |x| {
|
||||
stack.add_var(var_id, x);
|
||||
|
||||
let block = engine_state.get_block(block_id);
|
||||
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
|
||||
Ok(value) => Value::List {
|
||||
vals: value.collect(),
|
||||
span,
|
||||
},
|
||||
Ok(pipeline_data) => pipeline_data.into_value(),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
})
|
||||
|
@ -32,7 +32,7 @@ impl Command for Length {
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
_ => Ok(Value::Int {
|
||||
val: input.count() as i64,
|
||||
val: input.into_iter().count() as i64,
|
||||
span: call.head,
|
||||
}
|
||||
.into_pipeline_data()),
|
||||
|
@ -4,9 +4,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
use nu_protocol::{Example, PipelineData, ShellError, Signature, Span, Type, Value};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Size;
|
||||
@ -104,18 +102,16 @@ impl Command for Size {
|
||||
|
||||
fn size(call: &Call, input: PipelineData) -> Result<PipelineData, ShellError> {
|
||||
let span = call.head;
|
||||
Ok(input
|
||||
.map(move |v| match v.as_string() {
|
||||
Ok(s) => count(&s, span),
|
||||
Err(_) => Value::Error {
|
||||
error: ShellError::PipelineMismatch {
|
||||
expected: Type::String,
|
||||
expected_span: span,
|
||||
origin: span,
|
||||
},
|
||||
input.map(move |v| match v.as_string() {
|
||||
Ok(s) => count(&s, span),
|
||||
Err(_) => Value::Error {
|
||||
error: ShellError::PipelineMismatch {
|
||||
expected: Type::String,
|
||||
expected_span: span,
|
||||
origin: span,
|
||||
},
|
||||
})
|
||||
.into_pipeline_data())
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn count(contents: &str, span: Span) -> Value {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -54,9 +54,7 @@ fn split_chars(
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let span = call.head;
|
||||
|
||||
Ok(input
|
||||
.flat_map(move |x| split_chars_helper(&x, span))
|
||||
.into_pipeline_data())
|
||||
input.flat_map(move |x| split_chars_helper(&x, span))
|
||||
}
|
||||
|
||||
fn split_chars_helper(v: &Value, name: Span) -> Vec<Value> {
|
||||
|
@ -2,7 +2,7 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -54,9 +54,7 @@ fn split_column(
|
||||
let rest: Vec<Spanned<String>> = call.rest(engine_state, stack, 1)?;
|
||||
let collapse_empty = call.has_flag("collapse-empty");
|
||||
|
||||
Ok(input
|
||||
.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
|
||||
.into_pipeline_data())
|
||||
input.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span))
|
||||
}
|
||||
|
||||
fn split_column_helper(
|
||||
|
@ -2,7 +2,7 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
IntoPipelineData, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -45,9 +45,7 @@ fn split_row(
|
||||
let name_span = call.head;
|
||||
let separator: Spanned<String> = call.req(engine_state, stack, 0)?;
|
||||
|
||||
Ok(input
|
||||
.flat_map(move |x| split_row_helper(&x, &separator, name_span))
|
||||
.into_pipeline_data())
|
||||
input.flat_map(move |x| split_row_helper(&x, &separator, name_span))
|
||||
}
|
||||
|
||||
fn split_row_helper(v: &Value, separator: &Spanned<String>, name: Span) -> Vec<Value> {
|
||||
|
Reference in New Issue
Block a user