This commit is contained in:
JT
2021-10-25 17:01:02 +13:00
parent ab9d6b206d
commit b6d269e90a
63 changed files with 1075 additions and 1013 deletions

View File

@ -1,9 +1,10 @@
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
Example, ShellError, Signature, Span, SyntaxShape, Value,
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
#[derive(Clone)]
pub struct SubCommand;
impl Command for SubCommand {
@ -27,8 +28,8 @@ impl Command for SubCommand {
&self,
context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
into_binary(context, call, input)
}
@ -86,26 +87,28 @@ impl Command for SubCommand {
fn into_binary(
_context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let head = call.head;
// let column_paths: Vec<CellPath> = call.rest(context, 0)?;
input.map(head, 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(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)
// }
})
// Ok(ret)
// }
})
.into_pipeline_data())
}
fn int_to_endian(n: i64) -> Vec<u8> {

View File

@ -2,9 +2,10 @@ use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
Signature, Value,
IntoPipelineData, PipelineData, Signature, Value,
};
#[derive(Clone)]
pub struct Into;
impl Command for Into {
@ -24,12 +25,13 @@ impl Command for Into {
&self,
context: &EvaluationContext,
call: &Call,
_input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(Value::String {
val: get_full_help(&Into.signature(), &[], context),
span: call.head,
})
}
.into_pipeline_data())
}
}

View File

@ -1,9 +1,10 @@
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
Example, ShellError, Signature, Span, SyntaxShape, Value,
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
#[derive(Clone)]
pub struct SubCommand;
impl Command for SubCommand {
@ -27,8 +28,8 @@ impl Command for SubCommand {
&self,
context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
into_filesize(context, call, input)
}
@ -114,29 +115,31 @@ impl Command for SubCommand {
fn into_filesize(
_context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let head = call.head;
// let call_paths: Vec<ColumnPath> = args.rest(0)?;
input.map(head, move |v| {
action(v, head)
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())),
// )?;
// }
// 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)
// }
})
// Ok(ret)
// }
})
.into_pipeline_data())
}
pub fn action(input: Value, span: Span) -> Value {

View File

@ -1,9 +1,10 @@
use nu_protocol::{
ast::Call,
engine::{Command, EvaluationContext},
Example, IntoValueStream, ShellError, Signature, Span, SyntaxShape, Value,
Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
};
#[derive(Clone)]
pub struct SubCommand;
impl Command for SubCommand {
@ -27,8 +28,8 @@ impl Command for SubCommand {
&self,
context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
into_int(context, call, input)
}
@ -78,10 +79,8 @@ impl Command for SubCommand {
Example {
description: "Convert bool to integer",
example: "[$false, $true] | into int",
result: Some(Value::Stream {
stream: vec![Value::test_int(0), Value::test_int(1)]
.into_iter()
.into_value_stream(),
result: Some(Value::List {
vals: vec![Value::test_int(0), Value::test_int(1)],
span: Span::unknown(),
}),
},
@ -92,26 +91,28 @@ impl Command for SubCommand {
fn into_int(
_context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let head = call.head;
// let column_paths: Vec<CellPath> = call.rest(context, 0)?;
input.map(head, 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(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)
// }
})
// Ok(ret)
// }
})
.into_pipeline_data())
}
pub fn action(input: Value, span: Span) -> Value {