mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:25:38 +02:00
Rust 1.85, edition=2024 (#15741)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
authors = ["The Nushell Project Developers"]
|
||||
description = "Nushell's built-in commands"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
name = "nu-command"
|
||||
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-command"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
struct Arguments {
|
||||
@ -86,28 +86,32 @@ impl Command for BytesAdd {
|
||||
Example {
|
||||
description: "Add bytes `0x[AA]` to `0x[1F FF AA AA]`",
|
||||
example: "0x[1F FF AA AA] | bytes add 0x[AA]",
|
||||
result: Some(Value::binary(vec![0xAA, 0x1F, 0xFF, 0xAA, 0xAA],
|
||||
result: Some(Value::binary(
|
||||
vec![0xAA, 0x1F, 0xFF, 0xAA, 0xAA],
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Add bytes `0x[AA BB]` to `0x[1F FF AA AA]` at index 1",
|
||||
example: "0x[1F FF AA AA] | bytes add 0x[AA BB] --index 1",
|
||||
result: Some(Value::binary(vec![0x1F, 0xAA, 0xBB, 0xFF, 0xAA, 0xAA],
|
||||
result: Some(Value::binary(
|
||||
vec![0x1F, 0xAA, 0xBB, 0xFF, 0xAA, 0xAA],
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Add bytes `0x[11]` to `0x[FF AA AA]` at the end",
|
||||
example: "0x[FF AA AA] | bytes add 0x[11] --end",
|
||||
result: Some(Value::binary(vec![0xFF, 0xAA, 0xAA, 0x11],
|
||||
result: Some(Value::binary(
|
||||
vec![0xFF, 0xAA, 0xAA, 0x11],
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Add bytes `0x[11 22 33]` to `0x[FF AA AA]` at the end, at index 1(the index is start from end)",
|
||||
example: "0x[FF AA BB] | bytes add 0x[11 22 33] --end --index 1",
|
||||
result: Some(Value::binary(vec![0xFF, 0xAA, 0x11, 0x22, 0x33, 0xBB],
|
||||
result: Some(Value::binary(
|
||||
vec![0xFF, 0xAA, 0x11, 0x22, 0x33, 0xBB],
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::ops::Bound;
|
||||
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{IntRange, Range};
|
||||
|
||||
@ -67,7 +67,7 @@ impl Command for BytesAt {
|
||||
input: "value originates from here".into(),
|
||||
msg_span: call.head,
|
||||
input_span: call.head,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -148,8 +148,8 @@ fn map_value(input: &Value, args: &Arguments, head: Span) -> Value {
|
||||
return Value::error(
|
||||
ShellError::UnsupportedInput {
|
||||
msg: format!(
|
||||
"Absolute start position {start} was too large for your system arch."
|
||||
),
|
||||
"Absolute start position {start} was too large for your system arch."
|
||||
),
|
||||
input: args.range.to_string(),
|
||||
msg_span: span,
|
||||
input_span: span,
|
||||
|
@ -67,7 +67,7 @@ impl Command for BytesBuild {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "only binary data arguments are supported".to_string(),
|
||||
span: other.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::shell_error::io::IoError;
|
||||
use std::{
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
struct Arguments {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CellPathOnlyArgs};
|
||||
use nu_cmd_base::input_handler::{CellPathOnlyArgs, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
struct Arguments {
|
||||
@ -81,9 +81,7 @@ impl Command for BytesRemove {
|
||||
Example {
|
||||
description: "Remove contents",
|
||||
example: "0x[10 AA FF AA FF] | bytes remove 0x[10 AA]",
|
||||
result: Some(Value::test_binary (
|
||||
vec![0xFF, 0xAA, 0xFF],
|
||||
)),
|
||||
result: Some(Value::test_binary(vec![0xFF, 0xAA, 0xFF])),
|
||||
},
|
||||
Example {
|
||||
description: "Remove all occurrences of find binary in record field",
|
||||
@ -95,27 +93,23 @@ impl Command for BytesRemove {
|
||||
Example {
|
||||
description: "Remove occurrences of find binary from end",
|
||||
example: "0x[10 AA 10 BB CC AA 10] | bytes remove --end 0x[10]",
|
||||
result: Some(Value::test_binary (
|
||||
vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA],
|
||||
)),
|
||||
result: Some(Value::test_binary(vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA])),
|
||||
},
|
||||
Example {
|
||||
description: "Remove find binary from end not found",
|
||||
example: "0x[10 AA 10 BB CC AA 10] | bytes remove --end 0x[11]",
|
||||
result: Some(Value::test_binary (
|
||||
vec![0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA, 0x10],
|
||||
)),
|
||||
result: Some(Value::test_binary(vec![
|
||||
0x10, 0xAA, 0x10, 0xBB, 0xCC, 0xAA, 0x10,
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Remove all occurrences of find binary in table",
|
||||
example: "[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes remove 0x[11] ColA ColC",
|
||||
result: Some(Value::test_list (
|
||||
vec![Value::test_record(record! {
|
||||
"ColA" => Value::test_binary ( vec![0x12, 0x13],),
|
||||
"ColB" => Value::test_binary ( vec![0x14, 0x15, 0x16],),
|
||||
"ColC" => Value::test_binary ( vec![0x17, 0x18, 0x19],),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"ColA" => Value::test_binary ( vec![0x12, 0x13],),
|
||||
"ColB" => Value::test_binary ( vec![0x14, 0x15, 0x16],),
|
||||
"ColC" => Value::test_binary ( vec![0x17, 0x18, 0x19],),
|
||||
})])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
struct Arguments {
|
||||
@ -81,27 +81,21 @@ impl Command for BytesReplace {
|
||||
Example {
|
||||
description: "Find and replace contents",
|
||||
example: "0x[10 AA FF AA FF] | bytes replace 0x[10 AA] 0x[FF]",
|
||||
result: Some(Value::test_binary (
|
||||
vec![0xFF, 0xFF, 0xAA, 0xFF],
|
||||
)),
|
||||
result: Some(Value::test_binary(vec![0xFF, 0xFF, 0xAA, 0xFF])),
|
||||
},
|
||||
Example {
|
||||
description: "Find and replace all occurrences of find binary",
|
||||
example: "0x[10 AA 10 BB 10] | bytes replace --all 0x[10] 0x[A0]",
|
||||
result: Some(Value::test_binary (
|
||||
vec![0xA0, 0xAA, 0xA0, 0xBB, 0xA0],
|
||||
)),
|
||||
result: Some(Value::test_binary(vec![0xA0, 0xAA, 0xA0, 0xBB, 0xA0])),
|
||||
},
|
||||
Example {
|
||||
description: "Find and replace all occurrences of find binary in table",
|
||||
example: "[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes replace --all 0x[11] 0x[13] ColA ColC",
|
||||
result: Some(Value::test_list (
|
||||
vec![Value::test_record(record! {
|
||||
"ColA" => Value::test_binary(vec![0x13, 0x12, 0x13]),
|
||||
"ColB" => Value::test_binary(vec![0x14, 0x15, 0x16]),
|
||||
"ColC" => Value::test_binary(vec![0x17, 0x18, 0x19]),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"ColA" => Value::test_binary(vec![0x13, 0x12, 0x13]),
|
||||
"ColB" => Value::test_binary(vec![0x14, 0x15, 0x16]),
|
||||
"ColC" => Value::test_binary(vec![0x17, 0x18, 0x19]),
|
||||
})])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CellPathOnlyArgs};
|
||||
use nu_cmd_base::input_handler::{CellPathOnlyArgs, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::shell_error::io::IoError;
|
||||
use std::io::Read;
|
||||
|
@ -181,9 +181,9 @@ impl PartialEq for HashableValue {
|
||||
mod test {
|
||||
use super::*;
|
||||
use nu_protocol::{
|
||||
BlockId,
|
||||
ast::{CellPath, PathMember},
|
||||
engine::Closure,
|
||||
BlockId,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
@ -38,37 +38,35 @@ impl Command for Histogram {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Compute a histogram for the types of files, with frequency column named freq",
|
||||
description: "Compute a histogram for the types of files, with frequency column named freq",
|
||||
example: "ls | histogram type freq",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Compute a histogram for a list of numbers",
|
||||
example: "[1 2 1] | histogram",
|
||||
result: Some(Value::test_list (
|
||||
vec![Value::test_record(record! {
|
||||
"value" => Value::test_int(1),
|
||||
"count" => Value::test_int(2),
|
||||
"quantile" => Value::test_float(0.6666666666666666),
|
||||
"percentage" => Value::test_string("66.67%"),
|
||||
"frequency" => Value::test_string("******************************************************************"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(2),
|
||||
"count" => Value::test_int(1),
|
||||
"quantile" => Value::test_float(0.3333333333333333),
|
||||
"percentage" => Value::test_string("33.33%"),
|
||||
"frequency" => Value::test_string("*********************************"),
|
||||
})],
|
||||
)
|
||||
),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(1),
|
||||
"count" => Value::test_int(2),
|
||||
"quantile" => Value::test_float(0.6666666666666666),
|
||||
"percentage" => Value::test_string("66.67%"),
|
||||
"frequency" => Value::test_string("******************************************************************"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(2),
|
||||
"count" => Value::test_int(1),
|
||||
"quantile" => Value::test_float(0.3333333333333333),
|
||||
"percentage" => Value::test_string("33.33%"),
|
||||
"frequency" => Value::test_string("*********************************"),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Compute a histogram for a list of numbers, and percentage is based on the maximum value",
|
||||
example: "[1 2 3 1 1 1 2 2 1 1] | histogram --percentage-type relative",
|
||||
result: None,
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@ -115,7 +113,7 @@ impl Command for Histogram {
|
||||
err_message: "calc method can only be 'normalize' or 'relative'"
|
||||
.to_string(),
|
||||
span: inner.span,
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use print_positions::print_positions;
|
||||
@ -79,14 +79,12 @@ impl Command for Fill {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description:
|
||||
"Fill a string on the left side to a width of 15 with the character '─'",
|
||||
description: "Fill a string on the left side to a width of 15 with the character '─'",
|
||||
example: "'nushell' | fill --alignment l --character '─' --width 15",
|
||||
result: Some(Value::string("nushell────────", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Fill a string on the right side to a width of 15 with the character '─'",
|
||||
description: "Fill a string on the right side to a width of 15 with the character '─'",
|
||||
example: "'nushell' | fill --alignment r --character '─' --width 15",
|
||||
result: Some(Value::string("────────nushell", Span::test_data())),
|
||||
},
|
||||
@ -96,8 +94,7 @@ impl Command for Fill {
|
||||
result: Some(Value::string("──────────", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Fill a number on the left side to a width of 5 with the character '0'",
|
||||
description: "Fill a number on the left side to a width of 5 with the character '0'",
|
||||
example: "1 | fill --alignment right --character '0' --width 5",
|
||||
result: Some(Value::string("00001", Span::test_data())),
|
||||
},
|
||||
@ -107,8 +104,7 @@ impl Command for Fill {
|
||||
result: Some(Value::string("01.10", Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Fill a filesize on both sides to a width of 10 with the character '0'",
|
||||
description: "Fill a filesize on both sides to a width of 10 with the character '0'",
|
||||
example: "1kib | fill --alignment middle --character '0' --width 10",
|
||||
result: Some(Value::string("0001024000", Span::test_data())),
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
struct Arguments {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -204,7 +204,7 @@ fn value_to_path_member(val: &Value, span: Span) -> Result<PathMember, ShellErro
|
||||
from_type: other.get_type().to_string(),
|
||||
span: val.span(),
|
||||
help: None,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@ use chrono::{
|
||||
DateTime, Datelike, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone,
|
||||
Timelike, Utc,
|
||||
};
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
const HOUR: i32 = 60 * 60;
|
||||
@ -197,8 +197,7 @@ impl Command for IntoDatetime {
|
||||
result: example_result_1(1614434140_224600000),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Convert non-standard timestamp string, with timezone offset, to datetime using a custom format",
|
||||
description: "Convert non-standard timestamp string, with timezone offset, to datetime using a custom format",
|
||||
example: "'20210227_135540+0000' | into datetime --format '%Y%m%d_%H%M%S%z'",
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
result: example_result_1(1614434140_000000000),
|
||||
@ -210,8 +209,11 @@ impl Command for IntoDatetime {
|
||||
result: Some(Value::date(
|
||||
Local
|
||||
.from_local_datetime(
|
||||
&NaiveDateTime::parse_from_str("16.11.1984 8:00 am", "%d.%m.%Y %H:%M %P")
|
||||
.expect("date calculation should not fail in test"),
|
||||
&NaiveDateTime::parse_from_str(
|
||||
"16.11.1984 8:00 am",
|
||||
"%d.%m.%Y %H:%M %P",
|
||||
)
|
||||
.expect("date calculation should not fail in test"),
|
||||
)
|
||||
.unwrap()
|
||||
.with_timezone(Local::now().offset()),
|
||||
@ -219,8 +221,7 @@ impl Command for IntoDatetime {
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Convert nanosecond-precision unix timestamp to a datetime with offset from UTC",
|
||||
description: "Convert nanosecond-precision unix timestamp to a datetime with offset from UTC",
|
||||
example: "1614434140123456789 | into datetime --offset -5",
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
result: example_result_1(1614434140_123456789),
|
||||
@ -509,9 +510,8 @@ fn merge_record(record: &Record, head: Span, span: Span) -> Result<Value, ShellE
|
||||
),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span
|
||||
}
|
||||
);
|
||||
input_span: span,
|
||||
});
|
||||
};
|
||||
|
||||
// Empty fields are filled in a specific way: the time units bigger than the biggest provided fields are assumed to be current and smaller ones are zeroed.
|
||||
@ -640,7 +640,7 @@ fn merge_record(record: &Record, head: Span, span: Span) -> Result<Value, ShellE
|
||||
msg: "one of more values are incorrect and do not represent valid date".to_string(),
|
||||
val_span: head,
|
||||
call_span: span,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let time = match NaiveTime::from_hms_nano_opt(hour, minute, second, total_nanoseconds) {
|
||||
@ -650,7 +650,7 @@ fn merge_record(record: &Record, head: Span, span: Span) -> Result<Value, ShellE
|
||||
msg: "one of more values are incorrect and do not represent valid time".to_string(),
|
||||
val_span: head,
|
||||
call_span: span,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
let date_time = NaiveDateTime::new(date, time);
|
||||
@ -662,7 +662,7 @@ fn merge_record(record: &Record, head: Span, span: Span) -> Result<Value, ShellE
|
||||
msg: "Ambiguous or invalid timezone conversion".to_string(),
|
||||
val_span: head,
|
||||
call_span: span,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(Value::date(date_time_fixed, span))
|
||||
@ -711,7 +711,7 @@ fn parse_timezone_from_record(
|
||||
msg: "invalid timezone".to_string(),
|
||||
val_span: *span,
|
||||
call_span: *head,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(offset)
|
||||
@ -756,7 +756,7 @@ fn parse_with_format(val: &str, fmt: &str, head: Span) -> Result<Value, ()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::{action, DatetimeFormat, IntoDatetime, Zone};
|
||||
use super::{DatetimeFormat, IntoDatetime, Zone, action};
|
||||
use nu_protocol::Type::Error;
|
||||
|
||||
#[test]
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_parser::{parse_unit_value, DURATION_UNIT_GROUPS};
|
||||
use nu_protocol::{ast::Expr, Unit};
|
||||
use nu_parser::{DURATION_UNIT_GROUPS, parse_unit_value};
|
||||
use nu_protocol::{Unit, ast::Expr};
|
||||
|
||||
const NS_PER_US: i64 = 1_000;
|
||||
const NS_PER_MS: i64 = 1_000_000;
|
||||
@ -139,8 +139,7 @@ impl Command for IntoDuration {
|
||||
},
|
||||
Example {
|
||||
description: "Convert table of duration strings to table of duration values",
|
||||
example:
|
||||
"[[value]; ['1sec'] ['2min'] ['3hr'] ['4day'] ['5wk']] | into duration value",
|
||||
example: "[[value]; ['1sec'] ['2min'] ['3hr'] ['4day'] ['5wk']] | into duration value",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_duration(NS_PER_SEC),
|
||||
@ -325,9 +324,8 @@ fn merge_record(record: &Record, head: Span, span: Span) -> Result<Value, ShellE
|
||||
),
|
||||
input: "value originates from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span
|
||||
}
|
||||
);
|
||||
input_span: span,
|
||||
});
|
||||
};
|
||||
|
||||
let mut duration: i64 = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CellPathOnlyArgs};
|
||||
use nu_cmd_base::input_handler::{CellPathOnlyArgs, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use nu_utils::get_system_locale;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CellPathOnlyArgs};
|
||||
use nu_cmd_base::input_handler::{CellPathOnlyArgs, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
struct Arguments {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use chrono::{FixedOffset, TimeZone};
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use nu_utils::get_system_locale;
|
||||
@ -141,7 +141,7 @@ impl Command for IntoInt {
|
||||
err_message: "Endian must be one of native, little, big"
|
||||
.to_string(),
|
||||
span,
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => false,
|
||||
@ -270,7 +270,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
|
||||
help: None,
|
||||
},
|
||||
span,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -403,7 +403,7 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value {
|
||||
help: Some(e.to_string()),
|
||||
},
|
||||
head,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -456,7 +456,7 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
help: Some(r#"digits following "0b" can only be 0 or 1"#.to_string()),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(num)
|
||||
@ -486,7 +486,7 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||
from_type: "string".to_string(),
|
||||
span,
|
||||
help: Some(r#"octal digits following "0o" should be in 0-7"#.to_string()),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(num)
|
||||
|
@ -171,7 +171,7 @@ fn into_record(call: &Call, input: PipelineData) -> Result<PipelineData, ShellEr
|
||||
item.get_type(),
|
||||
),
|
||||
span,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_cmd_base::input_handler::{operate, CmdArgument};
|
||||
use nu_cmd_base::input_handler::{CmdArgument, operate};
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::Config;
|
||||
use nu_utils::get_system_locale;
|
||||
|
@ -436,60 +436,92 @@ mod test {
|
||||
#[test]
|
||||
fn test_datetime_ymdz_pattern() {
|
||||
assert!(DATETIME_YMDZ_RE.is_match("2022-01-01T00:00:00Z").unwrap());
|
||||
assert!(DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789Z")
|
||||
.unwrap());
|
||||
assert!(DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00+01:00")
|
||||
.unwrap());
|
||||
assert!(DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+01:00")
|
||||
.unwrap());
|
||||
assert!(DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00-01:00")
|
||||
.unwrap());
|
||||
assert!(DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-01:00")
|
||||
.unwrap());
|
||||
assert!(
|
||||
DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789Z")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00+01:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+01:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00-01:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-01:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(DATETIME_YMDZ_RE.is_match("'2022-01-01T00:00:00Z'").unwrap());
|
||||
|
||||
assert!(!DATETIME_YMDZ_RE.is_match("2022-01-01T00:00:00").unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE.is_match("2022-01-01T00:00:00.").unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789")
|
||||
.unwrap());
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(!DATETIME_YMDZ_RE.is_match("2022-01-01T00:00:00+01").unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00+01:0")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00+1:00")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+01")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+01:0")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+1:00")
|
||||
.unwrap());
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00+01:0")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00+1:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+01")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+01:0")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789+1:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(!DATETIME_YMDZ_RE.is_match("2022-01-01T00:00:00-01").unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00-01:0")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00-1:00")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-01")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-01:0")
|
||||
.unwrap());
|
||||
assert!(!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-1:00")
|
||||
.unwrap());
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00-01:0")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00-1:00")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-01")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-01:0")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
!DATETIME_YMDZ_RE
|
||||
.is_match("2022-01-01T00:00:00.123456789-1:00")
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -497,9 +529,11 @@ mod test {
|
||||
assert!(DATETIME_YMD_RE.is_match("2022-01-01").unwrap());
|
||||
assert!(DATETIME_YMD_RE.is_match("2022/01/01").unwrap());
|
||||
assert!(DATETIME_YMD_RE.is_match("2022-01-01T00:00:00").unwrap());
|
||||
assert!(DATETIME_YMD_RE
|
||||
.is_match("2022-01-01T00:00:00.000000000")
|
||||
.unwrap());
|
||||
assert!(
|
||||
DATETIME_YMD_RE
|
||||
.is_match("2022-01-01T00:00:00.000000000")
|
||||
.unwrap()
|
||||
);
|
||||
assert!(DATETIME_YMD_RE.is_match("'2022-01-01'").unwrap());
|
||||
|
||||
// The regex isn't this specific, but it would be nice if it were
|
||||
@ -508,9 +542,11 @@ mod test {
|
||||
// assert!(!DATETIME_YMD_RE.is_match("2022-01-01T24:00:00").unwrap());
|
||||
// assert!(!DATETIME_YMD_RE.is_match("2022-01-01T00:60:00").unwrap());
|
||||
// assert!(!DATETIME_YMD_RE.is_match("2022-01-01T00:00:60").unwrap());
|
||||
assert!(!DATETIME_YMD_RE
|
||||
.is_match("2022-01-01T00:00:00.0000000000")
|
||||
.unwrap());
|
||||
assert!(
|
||||
!DATETIME_YMD_RE
|
||||
.is_match("2022-01-01T00:00:00.0000000000")
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{ast::PathMember, IntoValue};
|
||||
use nu_protocol::{IntoValue, ast::PathMember};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SplitCellPath;
|
||||
@ -45,7 +45,7 @@ impl Command for SplitCellPath {
|
||||
let src_span = match input {
|
||||
// Early return on correct type and empty pipeline
|
||||
PipelineData::Value(Value::CellPath { val, .. }, _) => {
|
||||
return Ok(split_cell_path(val, head)?.into_pipeline_data())
|
||||
return Ok(split_cell_path(val, head)?.into_pipeline_data());
|
||||
}
|
||||
PipelineData::Empty => return Err(ShellError::PipelineEmpty { dst_span: head }),
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::database::{values::sqlite::nu_value_to_params, SQLiteDatabase};
|
||||
use crate::database::{SQLiteDatabase, values::sqlite::nu_value_to_params};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -4,8 +4,8 @@ mod values;
|
||||
use commands::add_commands_decls;
|
||||
|
||||
pub use values::{
|
||||
convert_sqlite_row_to_nu_value, convert_sqlite_value_to_nu_value, open_connection_in_memory,
|
||||
open_connection_in_memory_custom, values_to_sql, SQLiteDatabase, MEMORY_DB,
|
||||
MEMORY_DB, SQLiteDatabase, convert_sqlite_row_to_nu_value, convert_sqlite_value_to_nu_value,
|
||||
open_connection_in_memory, open_connection_in_memory_custom, values_to_sql,
|
||||
};
|
||||
|
||||
use nu_protocol::engine::StateWorkingSet;
|
||||
|
@ -2,6 +2,6 @@ pub mod definitions;
|
||||
pub mod sqlite;
|
||||
|
||||
pub use sqlite::{
|
||||
convert_sqlite_row_to_nu_value, convert_sqlite_value_to_nu_value, open_connection_in_memory,
|
||||
open_connection_in_memory_custom, values_to_sql, SQLiteDatabase, MEMORY_DB,
|
||||
MEMORY_DB, SQLiteDatabase, convert_sqlite_row_to_nu_value, convert_sqlite_value_to_nu_value,
|
||||
open_connection_in_memory, open_connection_in_memory_custom, values_to_sql,
|
||||
};
|
||||
|
@ -3,12 +3,12 @@ use super::definitions::{
|
||||
db_index::DbIndex, db_table::DbTable,
|
||||
};
|
||||
use nu_protocol::{
|
||||
shell_error::io::IoError, CustomValue, PipelineData, Record, ShellError, Signals, Span,
|
||||
Spanned, Value,
|
||||
CustomValue, PipelineData, Record, ShellError, Signals, Span, Spanned, Value,
|
||||
shell_error::io::IoError,
|
||||
};
|
||||
use rusqlite::{
|
||||
types::ValueRef, Connection, DatabaseName, Error as SqliteError, OpenFlags, Row, Statement,
|
||||
ToSql,
|
||||
Connection, DatabaseName, Error as SqliteError, OpenFlags, Row, Statement, ToSql,
|
||||
types::ValueRef,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
@ -435,7 +435,7 @@ pub fn value_to_sql(value: Value) -> Result<Box<dyn rusqlite::ToSql>, ShellError
|
||||
wrong_type: val.get_type().to_string(),
|
||||
dst_span: Span::unknown(),
|
||||
src_span: val.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use chrono::{Local, TimeZone};
|
||||
use human_date_parser::{from_human_time, ParseResult};
|
||||
use human_date_parser::{ParseResult, from_human_time};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -99,7 +99,7 @@ fn helper(value: Value, head: Span) -> Value {
|
||||
src_span: span,
|
||||
},
|
||||
span,
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,8 +43,7 @@ impl Command for DateNow {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Get the current date and format it according to the RFC 3339 standard.",
|
||||
description: "Get the current date and format it according to the RFC 3339 standard.",
|
||||
example: r#"date now | format date "%+""#,
|
||||
result: None,
|
||||
},
|
||||
@ -59,8 +58,7 @@ impl Command for DateNow {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Get current time and format it in the debug format (RFC 2822 with timezone)",
|
||||
description: "Get current time and format it in the debug format (RFC 2822 with timezone)",
|
||||
example: r#"date now | debug"#,
|
||||
result: None,
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
use chrono::{DateTime, FixedOffset, Local, LocalResult, TimeZone};
|
||||
use nu_protocol::{record, ShellError, Span, Value};
|
||||
use nu_protocol::{ShellError, Span, Value, record};
|
||||
|
||||
pub(crate) fn parse_date_from_string(
|
||||
input: &str,
|
||||
@ -109,8 +109,7 @@ pub(crate) fn generate_strftime_list(head: Span, show_parse_only_formats: bool)
|
||||
},
|
||||
FormatSpecification {
|
||||
spec: "%W",
|
||||
description:
|
||||
"Same as %U, but week 1 starts with the first Monday in that year instead.",
|
||||
description: "Same as %U, but week 1 starts with the first Monday in that year instead.",
|
||||
},
|
||||
FormatSpecification {
|
||||
spec: "%G",
|
||||
@ -226,8 +225,7 @@ pub(crate) fn generate_strftime_list(head: Span, show_parse_only_formats: bool)
|
||||
},
|
||||
FormatSpecification {
|
||||
spec: "%Z",
|
||||
description:
|
||||
"Local time zone name. Skips all non-whitespace characters during parsing.",
|
||||
description: "Local time zone name. Skips all non-whitespace characters during parsing.",
|
||||
},
|
||||
FormatSpecification {
|
||||
spec: "%z",
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_parser::{flatten_block, parse};
|
||||
use nu_protocol::{engine::StateWorkingSet, record};
|
||||
use serde_json::{json, Value as JsonValue};
|
||||
use serde_json::{Value as JsonValue, json};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Ast;
|
||||
@ -52,8 +52,7 @@ impl Command for Ast {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Print the ast of a pipeline with an error, as json, in a nushell table",
|
||||
description: "Print the ast of a pipeline with an error, as json, in a nushell table",
|
||||
example: "ast 'for x in 1..10 { echo $x ' --json | get block | from json",
|
||||
result: None,
|
||||
},
|
||||
@ -288,15 +287,15 @@ impl Command for Ast {
|
||||
|
||||
fn json_merge(a: &mut JsonValue, b: &JsonValue) {
|
||||
match (a, b) {
|
||||
(JsonValue::Object(ref mut a), JsonValue::Object(b)) => {
|
||||
(JsonValue::Object(a), JsonValue::Object(b)) => {
|
||||
for (k, v) in b {
|
||||
json_merge(a.entry(k).or_insert(JsonValue::Null), v);
|
||||
}
|
||||
}
|
||||
(JsonValue::Array(ref mut a), JsonValue::Array(b)) => {
|
||||
(JsonValue::Array(a), JsonValue::Array(b)) => {
|
||||
a.extend(b.clone());
|
||||
}
|
||||
(JsonValue::Array(ref mut a), JsonValue::Object(b)) => {
|
||||
(JsonValue::Array(a), JsonValue::Object(b)) => {
|
||||
a.extend([JsonValue::Object(b.clone())]);
|
||||
}
|
||||
(a, b) => {
|
||||
|
@ -78,8 +78,7 @@ impl Command for Debug {
|
||||
},
|
||||
Example {
|
||||
description: "Debug print a table",
|
||||
example:
|
||||
"[[version patch]; ['0.1.0' false] ['0.1.1' true] ['0.2.0' false]] | debug",
|
||||
example: "[[version patch]; ['0.1.0' false] ['0.1.1' true] ['0.2.0' false]] | debug",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_string("{version: 0.1.0, patch: false}"),
|
||||
|
@ -47,8 +47,7 @@ impl Command for Explain {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Explain a command within a closure",
|
||||
example:
|
||||
"explain {|| ls | sort-by name type --ignore-case | get name } | table --expand",
|
||||
example: "explain {|| ls | sort-by name type --ignore-case | get name } | table --expand",
|
||||
result: None,
|
||||
}]
|
||||
}
|
||||
|
@ -2,13 +2,13 @@
|
||||
// IMHO: it shall not take 300+ lines :)
|
||||
|
||||
use self::{global_horizontal_char::SetHorizontalChar, set_widths::SetWidths};
|
||||
use nu_protocol::engine::EngineState;
|
||||
use nu_protocol::Value;
|
||||
use nu_protocol::engine::EngineState;
|
||||
use nu_table::{string_width, string_wrap};
|
||||
use tabled::{
|
||||
grid::config::ColoredConfig,
|
||||
settings::{peaker::Priority, width::Wrap, Settings, Style},
|
||||
Table,
|
||||
grid::config::ColoredConfig,
|
||||
settings::{Settings, Style, peaker::Priority, width::Wrap},
|
||||
};
|
||||
|
||||
pub fn build_table(
|
||||
@ -199,8 +199,8 @@ fn push_empty_column(data: &mut Vec<Vec<String>>) {
|
||||
mod util {
|
||||
use crate::debug::explain::debug_string_without_formatting;
|
||||
use nu_engine::get_columns;
|
||||
use nu_protocol::engine::EngineState;
|
||||
use nu_protocol::Value;
|
||||
use nu_protocol::engine::EngineState;
|
||||
|
||||
/// Try to build column names and a table grid.
|
||||
pub fn collect_input(
|
||||
@ -263,10 +263,12 @@ mod util {
|
||||
} else if cols.is_empty() && records.is_empty() {
|
||||
vec![]
|
||||
} else if cols.len() == records.len() {
|
||||
vec![records
|
||||
.into_iter()
|
||||
.map(|s| debug_string_without_formatting(engine_state, &s))
|
||||
.collect()]
|
||||
vec![
|
||||
records
|
||||
.into_iter()
|
||||
.map(|s| debug_string_without_formatting(engine_state, &s))
|
||||
.collect(),
|
||||
]
|
||||
} else {
|
||||
records
|
||||
.into_iter()
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{
|
||||
ast::{Expr, Expression},
|
||||
DataSource, PipelineMetadata,
|
||||
ast::{Expr, Expression},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_engine::{command_prelude::*, get_eval_block_with_early_return};
|
||||
use nu_protocol::{
|
||||
engine::{Call, Closure, Command, EngineState, Stack},
|
||||
DataSource, PipelineData, PipelineMetadata, ShellError, Signature, SyntaxShape, Type, Value,
|
||||
engine::{Call, Closure, Command, EngineState, Stack},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -95,7 +95,7 @@ impl Command for MetadataSet {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{test_examples_with_commands, Metadata};
|
||||
use crate::{Metadata, test_examples_with_commands};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::{
|
||||
debugger::{DurationMode, Profiler, ProfilerOptions},
|
||||
engine::Closure,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
use web_time::Instant;
|
||||
|
||||
|
@ -119,7 +119,7 @@ the declaration may not be in scope.
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "expected closure, string, or int".into(),
|
||||
span: call.head,
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -250,7 +250,9 @@ impl Command for ViewSource {
|
||||
Example {
|
||||
description: "View the source of a custom command with flags and arguments",
|
||||
example: r#"def test [a?:any --b:int ...rest:string] { echo 'test' }; view source test"#,
|
||||
result: Some(Value::test_string("def test [ a?: any --b: int ...rest: string] { echo 'test' }")),
|
||||
result: Some(Value::test_string(
|
||||
"def test [ a?: any --b: int ...rest: string] { echo 'test' }",
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "View the source of a module",
|
||||
|
@ -42,8 +42,7 @@ impl Command for ConfigNu {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"pretty-print the internal `config.nu` file which is loaded before user's config",
|
||||
description: "pretty-print the internal `config.nu` file which is loaded before user's config",
|
||||
example: "config nu --default | nu-highlight",
|
||||
result: None,
|
||||
},
|
||||
|
2
crates/nu-command/src/env/load_env.rs
vendored
2
crates/nu-command/src/env/load_env.rs
vendored
@ -50,7 +50,7 @@ impl Command for LoadEnv {
|
||||
input: "value originated from here".into(),
|
||||
msg_span: span,
|
||||
input_span: input.span().unwrap_or(span),
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
2
crates/nu-command/src/env/source_env.rs
vendored
2
crates/nu-command/src/env/source_env.rs
vendored
@ -2,7 +2,7 @@ use nu_engine::{
|
||||
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return,
|
||||
redirect_env,
|
||||
};
|
||||
use nu_protocol::{engine::CommandType, shell_error::io::IoError, BlockId};
|
||||
use nu_protocol::{BlockId, engine::CommandType, shell_error::io::IoError};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Source a file for environment variables.
|
||||
|
@ -33,8 +33,8 @@ mod test_examples {
|
||||
};
|
||||
use nu_cmd_lang::{Break, Describe, Echo, If, Let, Mut};
|
||||
use nu_protocol::{
|
||||
engine::{Command, EngineState, StateWorkingSet},
|
||||
Type,
|
||||
engine::{Command, EngineState, StateWorkingSet},
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
@ -34,13 +34,11 @@ impl Command for IsAdmin {
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Return 'iamroot' if nushell is running with admin/root privileges, and 'iamnotroot' if not.",
|
||||
example: r#"if (is-admin) { "iamroot" } else { "iamnotroot" }"#,
|
||||
result: Some(Value::test_string("iamnotroot")),
|
||||
},
|
||||
]
|
||||
vec![Example {
|
||||
description: "Return 'iamroot' if nushell is running with admin/root privileges, and 'iamnotroot' if not.",
|
||||
example: r#"if (is-admin) { "iamroot" } else { "iamnotroot" }"#,
|
||||
result: Some(Value::test_string("iamnotroot")),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +56,7 @@ fn is_root_impl() -> bool {
|
||||
fn is_root_impl() -> bool {
|
||||
use windows::Win32::{
|
||||
Foundation::{CloseHandle, HANDLE},
|
||||
Security::{GetTokenInformation, TokenElevation, TOKEN_ELEVATION, TOKEN_QUERY},
|
||||
Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
||||
System::Threading::{GetCurrentProcess, OpenProcessToken},
|
||||
};
|
||||
|
||||
|
@ -6,8 +6,8 @@ use std::{
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
use nu_protocol::{
|
||||
engine::{FilterTag, Mailbox},
|
||||
Signals,
|
||||
engine::{FilterTag, Mailbox},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{engine::FilterTag, JobId};
|
||||
use nu_protocol::{JobId, engine::FilterTag};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JobSend;
|
||||
|
@ -1,15 +1,17 @@
|
||||
use std::{
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, AtomicU32},
|
||||
mpsc, Arc, Mutex,
|
||||
mpsc,
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use nu_engine::{command_prelude::*, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::{
|
||||
OutDest, Signals,
|
||||
engine::{Closure, CurrentJob, Job, Mailbox, Redirection, ThreadJob},
|
||||
report_shell_error, OutDest, Signals,
|
||||
report_shell_error,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,10 +1,11 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{
|
||||
JobId,
|
||||
engine::{FrozenJob, Job, ThreadJob},
|
||||
process::check_ok,
|
||||
shell_error, JobId,
|
||||
shell_error,
|
||||
};
|
||||
use nu_system::{kill_by_pid, ForegroundWaitStatus};
|
||||
use nu_system::{ForegroundWaitStatus, kill_by_pid};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JobUnfreeze;
|
||||
@ -59,13 +60,13 @@ impl Command for JobUnfreeze {
|
||||
return Err(ShellError::JobNotFound {
|
||||
id: id.get(),
|
||||
span: head,
|
||||
})
|
||||
});
|
||||
}
|
||||
Some(Job::Thread(ThreadJob { .. })) => {
|
||||
return Err(ShellError::JobNotFrozen {
|
||||
id: id.get(),
|
||||
span: head,
|
||||
})
|
||||
});
|
||||
}
|
||||
Some(Job::Frozen(FrozenJob { .. })) => jobs
|
||||
.remove_job(id)
|
||||
|
@ -2,7 +2,7 @@ use std::path::PathBuf;
|
||||
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::shell_error::{self, io::IoError};
|
||||
use nu_utils::filesystem::{have_permission, PermissionResult};
|
||||
use nu_utils::filesystem::{PermissionResult, have_permission};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Cd;
|
||||
|
@ -164,7 +164,7 @@ fn du_for_one_pattern(
|
||||
current_dir: &Path,
|
||||
span: Span,
|
||||
signals: Signals,
|
||||
) -> Result<impl Iterator<Item = Value> + Send, ShellError> {
|
||||
) -> Result<impl Iterator<Item = Value> + Send + use<>, ShellError> {
|
||||
let exclude = args.exclude.map_or(Ok(None), move |x| {
|
||||
Pattern::new(x.item.as_ref())
|
||||
.map(Some)
|
||||
|
@ -70,14 +70,12 @@ impl Command for Glob {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Search for files and folders that begin with uppercase C or lowercase c",
|
||||
description: "Search for files and folders that begin with uppercase C or lowercase c",
|
||||
example: r#"glob "[Cc]*""#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Search for files and folders like abc or xyz substituting a character for ?",
|
||||
description: "Search for files and folders like abc or xyz substituting a character for ?",
|
||||
example: r#"glob "{a?c,x?z}""#,
|
||||
result: None,
|
||||
},
|
||||
@ -201,7 +199,7 @@ impl Command for Glob {
|
||||
span: Some(glob_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -220,7 +218,7 @@ impl Command for Glob {
|
||||
span: Some(glob_span),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@ use nu_engine::glob_from;
|
||||
use nu_engine::{command_prelude::*, env::current_dir};
|
||||
use nu_glob::MatchOptions;
|
||||
use nu_path::{expand_path_with, expand_to_real_path};
|
||||
use nu_protocol::{shell_error::io::IoError, DataSource, NuGlob, PipelineMetadata, Signals};
|
||||
use nu_protocol::{DataSource, NuGlob, PipelineMetadata, Signals, shell_error::io::IoError};
|
||||
use pathdiff::diff_paths;
|
||||
use rayon::prelude::*;
|
||||
#[cfg(unix)]
|
||||
@ -13,7 +13,7 @@ use std::os::unix::fs::PermissionsExt;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
path::PathBuf,
|
||||
sync::{mpsc, Arc, Mutex},
|
||||
sync::{Arc, Mutex, mpsc},
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@ -189,20 +189,17 @@ impl Command for Ls {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"List only the names (not paths) of all dirs in your home directory which have not been modified in 7 days",
|
||||
description: "List only the names (not paths) of all dirs in your home directory which have not been modified in 7 days",
|
||||
example: "ls -as ~ | where type == dir and modified < ((date now) - 7day)",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Recursively list all files and subdirectories under the current directory using a glob pattern",
|
||||
description: "Recursively list all files and subdirectories under the current directory using a glob pattern",
|
||||
example: "ls -a **/*",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Recursively list *.rs and *.toml files using the glob command",
|
||||
description: "Recursively list *.rs and *.toml files using the glob command",
|
||||
example: "ls ...(glob **/*.{rs,toml})",
|
||||
result: None,
|
||||
},
|
||||
@ -799,8 +796,8 @@ mod windows_helper {
|
||||
use std::os::windows::prelude::OsStrExt;
|
||||
use windows::Win32::Foundation::FILETIME;
|
||||
use windows::Win32::Storage::FileSystem::{
|
||||
FindClose, FindFirstFileW, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY,
|
||||
FILE_ATTRIBUTE_REPARSE_POINT, WIN32_FIND_DATAW,
|
||||
FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_REPARSE_POINT, FindClose,
|
||||
FindFirstFileW, WIN32_FIND_DATAW,
|
||||
};
|
||||
use windows::Win32::System::SystemServices::{
|
||||
IO_REPARSE_TAG_MOUNT_POINT, IO_REPARSE_TAG_SYMLINK,
|
||||
@ -858,7 +855,7 @@ mod windows_helper {
|
||||
);
|
||||
}
|
||||
|
||||
let file_size = (find_data.nFileSizeHigh as u64) << 32 | find_data.nFileSizeLow as u64;
|
||||
let file_size = ((find_data.nFileSizeHigh as u64) << 32) | find_data.nFileSizeLow as u64;
|
||||
record.push("size", Value::filesize(file_size as i64, span));
|
||||
|
||||
if long {
|
||||
|
@ -1,10 +1,9 @@
|
||||
#[allow(deprecated)]
|
||||
use nu_engine::{command_prelude::*, current_dir, eval_call};
|
||||
use nu_protocol::{
|
||||
ast,
|
||||
DataSource, NuGlob, PipelineMetadata, ast,
|
||||
debugger::{WithDebug, WithoutDebug},
|
||||
shell_error::{self, io::IoError},
|
||||
DataSource, NuGlob, PipelineMetadata,
|
||||
};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@ -290,7 +289,7 @@ impl Command for Open {
|
||||
| rename extension command
|
||||
"#,
|
||||
result: None,
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,8 @@ use nu_engine::{command_prelude::*, env::current_dir};
|
||||
use nu_glob::MatchOptions;
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::{
|
||||
report_shell_error,
|
||||
NuGlob, report_shell_error,
|
||||
shell_error::{self, io::IoError},
|
||||
NuGlob,
|
||||
};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::prelude::FileTypeExt;
|
||||
@ -71,8 +70,7 @@ impl Command for Rm {
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
let mut examples = vec![Example {
|
||||
description:
|
||||
"Delete, or move a file to the trash (based on the 'always_trash' config option)",
|
||||
description: "Delete, or move a file to the trash (based on the 'always_trash' config option)",
|
||||
example: "rm file.txt",
|
||||
result: None,
|
||||
}];
|
||||
|
@ -4,8 +4,8 @@ use nu_engine::get_eval_block;
|
||||
use nu_engine::{command_prelude::*, current_dir};
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::{
|
||||
ast, byte_stream::copy_with_signals, process::ChildPipe, shell_error::io::IoError,
|
||||
ByteStreamSource, DataSource, OutDest, PipelineMetadata, Signals,
|
||||
ByteStreamSource, DataSource, OutDest, PipelineMetadata, Signals, ast,
|
||||
byte_stream::copy_with_signals, process::ChildPipe, shell_error::io::IoError,
|
||||
};
|
||||
use std::{
|
||||
fs::File,
|
||||
@ -264,8 +264,7 @@ impl Command for Save {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Show the extensions for which the `save` command will automatically serialize",
|
||||
description: "Show the extensions for which the `save` command will automatically serialize",
|
||||
example: r#"scope commands
|
||||
| where name starts-with "to "
|
||||
| insert extension { get name | str replace -r "^to " "" | $"*.($in)" }
|
||||
|
@ -1,6 +1,6 @@
|
||||
#[allow(deprecated)]
|
||||
use nu_engine::{command_prelude::*, current_dir};
|
||||
use nu_protocol::{shell_error::io::IoError, NuGlob};
|
||||
use nu_protocol::{NuGlob, shell_error::io::IoError};
|
||||
use std::path::PathBuf;
|
||||
use uu_cp::{BackupMode, CopyMode, UpdateMode};
|
||||
|
||||
@ -274,7 +274,7 @@ impl Command for UCp {
|
||||
span: None,
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
// TODO: What should we do in place of set_exit_code?
|
||||
|
@ -1,7 +1,7 @@
|
||||
#[allow(deprecated)]
|
||||
use nu_engine::{command_prelude::*, current_dir};
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::{shell_error::io::IoError, NuGlob};
|
||||
use nu_protocol::{NuGlob, shell_error::io::IoError};
|
||||
use std::{ffi::OsString, path::PathBuf};
|
||||
use uu_mv::{BackupMode, UpdateMode};
|
||||
|
||||
|
@ -3,9 +3,9 @@ use filetime::FileTime;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_glob::{glob, is_glob};
|
||||
use nu_path::expand_path_with;
|
||||
use nu_protocol::{shell_error::io::IoError, NuGlob};
|
||||
use nu_protocol::{NuGlob, shell_error::io::IoError};
|
||||
use std::path::PathBuf;
|
||||
use uu_touch::{error::TouchError, ChangeTimes, InputFile, Options, Source};
|
||||
use uu_touch::{ChangeTimes, InputFile, Options, Source, error::TouchError};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UTouch;
|
||||
|
@ -1,11 +1,11 @@
|
||||
use notify_debouncer_full::{
|
||||
new_debouncer,
|
||||
notify::{
|
||||
event::{DataChange, ModifyKind, RenameMode},
|
||||
EventKind, RecursiveMode, Watcher,
|
||||
event::{DataChange, ModifyKind, RenameMode},
|
||||
},
|
||||
};
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::{
|
||||
engine::{Closure, StateWorkingSet},
|
||||
format_shell_error,
|
||||
@ -13,7 +13,7 @@ use nu_protocol::{
|
||||
};
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::mpsc::{channel, RecvTimeoutError},
|
||||
sync::mpsc::{RecvTimeoutError, channel},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
@ -89,7 +89,7 @@ impl Command for Watch {
|
||||
err.kind(),
|
||||
path_arg.span,
|
||||
PathBuf::from(path_no_whitespace),
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
@ -108,7 +108,7 @@ impl Command for Watch {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "Debounce duration is invalid".to_string(),
|
||||
span: val.span,
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
None => DEFAULT_WATCH_DEBOUNCE_DURATION,
|
||||
@ -128,7 +128,7 @@ impl Command for Watch {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "Glob pattern is invalid".to_string(),
|
||||
span: glob.span,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::utils::chain_error_with_input;
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_protocol::engine::Closure;
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::Signals;
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ChunkBy;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{shell_error::io::IoError, ListStream};
|
||||
use nu_protocol::{ListStream, shell_error::io::IoError};
|
||||
use std::{
|
||||
io::{BufRead, Cursor, ErrorKind},
|
||||
num::NonZeroUsize,
|
||||
|
@ -106,7 +106,7 @@ fn getcol(head: Span, input: PipelineData) -> Result<PipelineData, ShellError> {
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: head,
|
||||
src_span: other.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -55,8 +55,7 @@ impl Command for Default {
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Get the env value of `MY_ENV` with a default value 'abc' if not present",
|
||||
description: "Get the env value of `MY_ENV` with a default value 'abc' if not present",
|
||||
example: "$env | get --ignore-errors MY_ENV | default 'abc'",
|
||||
result: Some(Value::test_string("abc")),
|
||||
},
|
||||
|
@ -159,7 +159,7 @@ impl Command for DropNth {
|
||||
head,
|
||||
engine_state.signals().clone(),
|
||||
metadata,
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::utils::chain_error_with_input;
|
||||
use nu_engine::{command_prelude::*, ClosureEval, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEval, ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -78,8 +78,7 @@ with 'transpose' first."#
|
||||
},
|
||||
Example {
|
||||
example: r#"[1 2 3] | enumerate | each {|e| if $e.item == 2 { $"found 2 at ($e.index)!"} }"#,
|
||||
description:
|
||||
"Iterate over each element, producing a list showing indexes of any 2s",
|
||||
description: "Iterate over each element, producing a list showing indexes of any 2s",
|
||||
result: Some(Value::test_list(vec![Value::test_string("found 2 at 1!")])),
|
||||
},
|
||||
Example {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::utils::chain_error_with_input;
|
||||
use nu_engine::{command_prelude::*, ClosureEval, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEval, ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -76,7 +76,10 @@ impl Command for Find {
|
||||
Example {
|
||||
description: "Search and highlight text for a term in a string. Note that regular search is case insensitive",
|
||||
example: r#"'Cargo.toml' | find cargo"#,
|
||||
result: Some(Value::test_string("\u{1b}[37m\u{1b}[0m\u{1b}[41;37mCargo\u{1b}[0m\u{1b}[37m.toml\u{1b}[0m".to_owned())),
|
||||
result: Some(Value::test_string(
|
||||
"\u{1b}[37m\u{1b}[0m\u{1b}[41;37mCargo\u{1b}[0m\u{1b}[37m.toml\u{1b}[0m"
|
||||
.to_owned(),
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Search a number or a file size in a list of numbers",
|
||||
@ -90,7 +93,14 @@ impl Command for Find {
|
||||
description: "Search a char in a list of string",
|
||||
example: r#"[moe larry curly] | find l"#,
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_string("\u{1b}[37m\u{1b}[0m\u{1b}[41;37ml\u{1b}[0m\u{1b}[37marry\u{1b}[0m"), Value::test_string("\u{1b}[37mcur\u{1b}[0m\u{1b}[41;37ml\u{1b}[0m\u{1b}[37my\u{1b}[0m")],
|
||||
vec![
|
||||
Value::test_string(
|
||||
"\u{1b}[37m\u{1b}[0m\u{1b}[41;37ml\u{1b}[0m\u{1b}[37marry\u{1b}[0m",
|
||||
),
|
||||
Value::test_string(
|
||||
"\u{1b}[37mcur\u{1b}[0m\u{1b}[41;37ml\u{1b}[0m\u{1b}[37my\u{1b}[0m",
|
||||
),
|
||||
],
|
||||
Span::test_data(),
|
||||
)),
|
||||
},
|
||||
@ -119,28 +129,24 @@ impl Command for Find {
|
||||
Example {
|
||||
description: "Find value in records using regex",
|
||||
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find --regex "nu""#,
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_record(record! {
|
||||
"version" => Value::test_string("0.1.0"),
|
||||
"name" => Value::test_string("nushell".to_string()),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"version" => Value::test_string("0.1.0"),
|
||||
"name" => Value::test_string("nushell".to_string()),
|
||||
})])),
|
||||
},
|
||||
Example {
|
||||
description: "Find inverted values in records using regex",
|
||||
example: r#"[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find --regex "nu" --invert"#,
|
||||
result: Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record!{
|
||||
"version" => Value::test_string("0.1.1"),
|
||||
"name" => Value::test_string("fish".to_string()),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"version" => Value::test_string("0.2.0"),
|
||||
"name" =>Value::test_string("zsh".to_string()),
|
||||
}),
|
||||
],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"version" => Value::test_string("0.1.1"),
|
||||
"name" => Value::test_string("fish".to_string()),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"version" => Value::test_string("0.2.0"),
|
||||
"name" =>Value::test_string("zsh".to_string()),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Find value in list using regex",
|
||||
@ -166,20 +172,18 @@ impl Command for Find {
|
||||
},
|
||||
Example {
|
||||
description: "Remove ANSI sequences from result",
|
||||
example:"[[foo bar]; [abc 123] [def 456]] | find --no-highlight 123",
|
||||
example: "[[foo bar]; [abc 123] [def 456]] | find --no-highlight 123",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(record! {
|
||||
"foo" => Value::test_string("abc"),
|
||||
"bar" => Value::test_int(123)
|
||||
}
|
||||
)],
|
||||
})],
|
||||
Span::test_data(),
|
||||
))
|
||||
)),
|
||||
},
|
||||
Example {
|
||||
description: "Find and highlight text in specific columns",
|
||||
example:
|
||||
"[[col1 col2 col3]; [moe larry curly] [larry curly moe]] | find moe --columns [col1]",
|
||||
example: "[[col1 col2 col3]; [moe larry curly] [larry curly moe]] | find moe --columns [col1]",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_record(record! {
|
||||
"col1" => Value::test_string(
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{shell_error::io::IoError, Signals};
|
||||
use nu_protocol::{Signals, shell_error::io::IoError};
|
||||
use std::io::Read;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -47,26 +47,25 @@ impl Command for Flatten {
|
||||
Example {
|
||||
description: "flatten a table",
|
||||
example: "[[N, u, s, h, e, l, l]] | flatten ",
|
||||
result: Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_string("N"),
|
||||
Value::test_string("u"),
|
||||
Value::test_string("s"),
|
||||
Value::test_string("h"),
|
||||
Value::test_string("e"),
|
||||
Value::test_string("l"),
|
||||
Value::test_string("l")],
|
||||
))
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_string("N"),
|
||||
Value::test_string("u"),
|
||||
Value::test_string("s"),
|
||||
Value::test_string("h"),
|
||||
Value::test_string("e"),
|
||||
Value::test_string("l"),
|
||||
Value::test_string("l"),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "flatten a table, get the first item",
|
||||
example: "[[N, u, s, h, e, l, l]] | flatten | first",
|
||||
result: None,//Some(Value::test_string("N")),
|
||||
result: None, //Some(Value::test_string("N")),
|
||||
},
|
||||
Example {
|
||||
description: "flatten a column having a nested table",
|
||||
example: "[[origin, people]; [Ecuador, ([[name, meal]; ['Andres', 'arepa']])]] | flatten --all | get meal",
|
||||
result: None,//Some(Value::test_string("arepa")),
|
||||
result: None, //Some(Value::test_string("arepa")),
|
||||
},
|
||||
Example {
|
||||
description: "restrict the flattening by passing column names",
|
||||
@ -109,7 +108,7 @@ impl Command for Flatten {
|
||||
],
|
||||
Span::test_data(),
|
||||
)),
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{ast::PathMember, Signals};
|
||||
use nu_protocol::{Signals, ast::PathMember};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Get;
|
||||
@ -75,8 +75,7 @@ If multiple cell paths are given, this will produce a list of values."#
|
||||
result: Some(Value::test_string("A0")),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Extract the name of the 3rd record in a list (same as `ls | $in.name.2`)",
|
||||
description: "Extract the name of the 3rd record in a list (same as `ls | $in.name.2`)",
|
||||
example: "ls | get name.2",
|
||||
result: None,
|
||||
},
|
||||
@ -175,7 +174,7 @@ fn action(
|
||||
wrong_type: "nothing".into(),
|
||||
dst_span: span,
|
||||
src_span: val.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use indexmap::IndexMap;
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_protocol::{engine::Closure, FromValue, IntoValue};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::{FromValue, IntoValue, engine::Closure};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GroupBy;
|
||||
@ -167,7 +167,7 @@ impl Command for GroupBy {
|
||||
})],
|
||||
),
|
||||
}),
|
||||
}))
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
description: "Group items by multiple columns' values",
|
||||
@ -212,7 +212,7 @@ impl Command for GroupBy {
|
||||
})
|
||||
]),
|
||||
}),
|
||||
]))
|
||||
])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use nu_engine::{command_prelude::*, ClosureEval, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEval, ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::ast::PathMember;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::{engine::Closure, shell_error::io::IoError};
|
||||
use std::{sync::mpsc, thread};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::utils::chain_error_with_input;
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -95,8 +95,7 @@ impl Command for Items {
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
example:
|
||||
"{ new: york, san: francisco } | items {|key, value| echo $'($key) ($value)' }",
|
||||
example: "{ new: york, san: francisco } | items {|key, value| echo $'($key) ($value)' }",
|
||||
description: "Iterate over each key-value pair of a record",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::common::{do_merge, typecheck_merge, ListMerge, MergeStrategy};
|
||||
use super::common::{ListMerge, MergeStrategy, do_merge, typecheck_merge};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::common::{do_merge, typecheck_merge, MergeStrategy};
|
||||
use super::common::{MergeStrategy, do_merge, typecheck_merge};
|
||||
use nu_engine::command_prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -51,50 +51,44 @@ impl Command for Move {
|
||||
Example {
|
||||
example: "[[name value index]; [foo a 1] [bar b 2] [baz c 3]] | move index --before name",
|
||||
description: "Move a column before the first column",
|
||||
result:
|
||||
Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(1),
|
||||
"name" => Value::test_string("foo"),
|
||||
"value" => Value::test_string("a"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(2),
|
||||
"name" => Value::test_string("bar"),
|
||||
"value" => Value::test_string("b"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(3),
|
||||
"name" => Value::test_string("baz"),
|
||||
"value" => Value::test_string("c"),
|
||||
}),
|
||||
],
|
||||
))
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(1),
|
||||
"name" => Value::test_string("foo"),
|
||||
"value" => Value::test_string("a"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(2),
|
||||
"name" => Value::test_string("bar"),
|
||||
"value" => Value::test_string("b"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(3),
|
||||
"name" => Value::test_string("baz"),
|
||||
"value" => Value::test_string("c"),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
example: "[[name value index]; [foo a 1] [bar b 2] [baz c 3]] | move value name --after index",
|
||||
description: "Move multiple columns after the last column and reorder them",
|
||||
result:
|
||||
Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(1),
|
||||
"value" => Value::test_string("a"),
|
||||
"name" => Value::test_string("foo"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(2),
|
||||
"value" => Value::test_string("b"),
|
||||
"name" => Value::test_string("bar"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(3),
|
||||
"value" => Value::test_string("c"),
|
||||
"name" => Value::test_string("baz"),
|
||||
}),
|
||||
],
|
||||
))
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(1),
|
||||
"value" => Value::test_string("a"),
|
||||
"name" => Value::test_string("foo"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(2),
|
||||
"value" => Value::test_string("b"),
|
||||
"name" => Value::test_string("bar"),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"index" => Value::test_int(3),
|
||||
"value" => Value::test_string("c"),
|
||||
"name" => Value::test_string("baz"),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
example: "{ name: foo, value: a, index: 1 } | move name --before index",
|
||||
@ -103,7 +97,7 @@ impl Command for Move {
|
||||
"value" => Value::test_string("a"),
|
||||
"name" => Value::test_string("foo"),
|
||||
"index" => Value::test_int(1),
|
||||
}))
|
||||
})),
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -140,7 +134,7 @@ impl Command for Move {
|
||||
span: Some(head),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
return Err(ShellError::GenericError {
|
||||
@ -149,7 +143,7 @@ impl Command for Move {
|
||||
span: Some(head),
|
||||
help: None,
|
||||
inner: vec![],
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::chain_error_with_input;
|
||||
use nu_engine::{command_prelude::*, ClosureEvalOnce};
|
||||
use nu_protocol::{engine::Closure, Signals};
|
||||
use nu_engine::{ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::{Signals, engine::Closure};
|
||||
use rayon::prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -49,8 +49,7 @@ impl Command for ParEach {
|
||||
vec![
|
||||
Example {
|
||||
example: "[1 2 3] | par-each {|e| $e * 2 }",
|
||||
description:
|
||||
"Multiplies each number. Note that the list will become arbitrarily disordered.",
|
||||
description: "Multiplies each number. Note that the list will become arbitrarily disordered.",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
@ -82,8 +81,7 @@ impl Command for ParEach {
|
||||
},
|
||||
Example {
|
||||
example: r#"[1 2 3] | enumerate | par-each { |e| if $e.item == 2 { $"found 2 at ($e.index)!"} }"#,
|
||||
description:
|
||||
"Iterate over each element, producing a list showing indexes of any 2s",
|
||||
description: "Iterate over each element, producing a list showing indexes of any 2s",
|
||||
result: Some(Value::test_list(vec![Value::test_string("found 2 at 1!")])),
|
||||
},
|
||||
]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -52,8 +52,7 @@ impl Command for Reduce {
|
||||
result: Some(Value::test_int(-8)),
|
||||
},
|
||||
Example {
|
||||
example:
|
||||
"[ 8 7 6 ] | enumerate | reduce --fold 0 {|it, acc| $acc + $it.item + $it.index }",
|
||||
example: "[ 8 7 6 ] | enumerate | reduce --fold 0 {|it, acc| $acc + $it.item + $it.index }",
|
||||
description: "Sum values of a list, plus their indexes",
|
||||
result: Some(Value::test_int(24)),
|
||||
},
|
||||
@ -74,14 +73,12 @@ impl Command for Reduce {
|
||||
},
|
||||
Example {
|
||||
example: r#"['foo.gz', 'bar.gz', 'baz.gz'] | enumerate | reduce --fold '' {|str all| $"($all)(if $str.index != 0 {'; '})($str.index + 1)-($str.item)" }"#,
|
||||
description:
|
||||
"Add ascending numbers to each of the filenames, and join with semicolons.",
|
||||
description: "Add ascending numbers to each of the filenames, and join with semicolons.",
|
||||
result: Some(Value::test_string("1-foo.gz; 2-bar.gz; 3-baz.gz")),
|
||||
},
|
||||
Example {
|
||||
example: r#"let s = "Str"; 0..2 | reduce --fold '' {|it, acc| $acc + $s}"#,
|
||||
description:
|
||||
"Concatenate a string with itself, using a range to determine the number of times.",
|
||||
description: "Concatenate a string with itself, using a range to determine the number of times.",
|
||||
result: Some(Value::test_string("StrStrStr")),
|
||||
},
|
||||
Example {
|
||||
@ -92,7 +89,7 @@ impl Command for Reduce {
|
||||
"b" => Value::test_int(2),
|
||||
"c" => Value::test_int(3),
|
||||
))),
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@ -140,7 +137,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
use crate::{test_examples_with_commands, Merge};
|
||||
use crate::{Merge, test_examples_with_commands};
|
||||
|
||||
test_examples_with_commands(Reduce {}, &[&Merge])
|
||||
}
|
||||
|
@ -109,21 +109,17 @@ impl Command for Reject {
|
||||
Example {
|
||||
description: "Reject a column in a table",
|
||||
example: "[[a, b]; [1, 2]] | reject a",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_record(record! {
|
||||
"b" => Value::test_int(2),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"b" => Value::test_int(2),
|
||||
})])),
|
||||
},
|
||||
Example {
|
||||
description: "Reject a row in a table",
|
||||
example: "[[a, b]; [1, 2] [3, 4]] | reject 1",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_record(record! {
|
||||
"a" => Value::test_int(1),
|
||||
"b" => Value::test_int(2),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"a" => Value::test_int(1),
|
||||
"b" => Value::test_int(2),
|
||||
})])),
|
||||
},
|
||||
Example {
|
||||
description: "Reject the specified field in a record",
|
||||
|
@ -1,5 +1,5 @@
|
||||
use indexmap::IndexMap;
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -146,24 +146,27 @@ fn rename(
|
||||
let span = item.span();
|
||||
match item {
|
||||
Value::Record { val: record, .. } => {
|
||||
let record =
|
||||
if let Some(closure) = &mut closure {
|
||||
record
|
||||
.into_owned().into_iter()
|
||||
.map(|(col, val)| {
|
||||
let col = Value::string(col, span);
|
||||
let data = closure.run_with_value(col)?;
|
||||
let col = data.collect_string_strict(span)?.0;
|
||||
Ok((col, val))
|
||||
})
|
||||
.collect::<Result<Record, _>>()
|
||||
} else {
|
||||
match &specified_column {
|
||||
Some(columns) => {
|
||||
// record columns are unique so we can track the number
|
||||
// of renamed columns to check if any were missed
|
||||
let mut renamed = 0;
|
||||
let record = record.into_owned().into_iter().map(|(col, val)| {
|
||||
let record = if let Some(closure) = &mut closure {
|
||||
record
|
||||
.into_owned()
|
||||
.into_iter()
|
||||
.map(|(col, val)| {
|
||||
let col = Value::string(col, span);
|
||||
let data = closure.run_with_value(col)?;
|
||||
let col = data.collect_string_strict(span)?.0;
|
||||
Ok((col, val))
|
||||
})
|
||||
.collect::<Result<Record, _>>()
|
||||
} else {
|
||||
match &specified_column {
|
||||
Some(columns) => {
|
||||
// record columns are unique so we can track the number
|
||||
// of renamed columns to check if any were missed
|
||||
let mut renamed = 0;
|
||||
let record = record
|
||||
.into_owned()
|
||||
.into_iter()
|
||||
.map(|(col, val)| {
|
||||
let col = if let Some(col) = columns.get(&col) {
|
||||
renamed += 1;
|
||||
col.clone()
|
||||
@ -172,36 +175,40 @@ fn rename(
|
||||
};
|
||||
|
||||
(col, val)
|
||||
}).collect::<Record>();
|
||||
|
||||
let missing_column = if renamed < columns.len() {
|
||||
columns.iter().find_map(|(col, new_col)| {
|
||||
(!record.contains(new_col)).then_some(col)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(missing) = missing_column {
|
||||
Err(ShellError::UnsupportedInput {
|
||||
msg: format!("The column '{missing}' does not exist in the input"),
|
||||
input: "value originated from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
})
|
||||
} else {
|
||||
Ok(record)
|
||||
}
|
||||
}
|
||||
None => Ok(record
|
||||
.into_owned().into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, (col, val))| {
|
||||
(columns.get(i).cloned().unwrap_or(col), val)
|
||||
})
|
||||
.collect()),
|
||||
.collect::<Record>();
|
||||
|
||||
let missing_column = if renamed < columns.len() {
|
||||
columns.iter().find_map(|(col, new_col)| {
|
||||
(!record.contains(new_col)).then_some(col)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(missing) = missing_column {
|
||||
Err(ShellError::UnsupportedInput {
|
||||
msg: format!(
|
||||
"The column '{missing}' does not exist in the input"
|
||||
),
|
||||
input: "value originated from here".into(),
|
||||
msg_span: head,
|
||||
input_span: span,
|
||||
})
|
||||
} else {
|
||||
Ok(record)
|
||||
}
|
||||
}
|
||||
};
|
||||
None => Ok(record
|
||||
.into_owned()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, (col, val))| {
|
||||
(columns.get(i).cloned().unwrap_or(col), val)
|
||||
})
|
||||
.collect()),
|
||||
}
|
||||
};
|
||||
|
||||
match record {
|
||||
Ok(record) => Value::record(record, span),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{ast::PathMember, PipelineIterator};
|
||||
use nu_protocol::{PipelineIterator, ast::PathMember};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -116,11 +116,9 @@ produce a table, a list will produce a list, and a record will produce a record.
|
||||
Example {
|
||||
description: "Select a column in a table",
|
||||
example: "[{a: a b: b}] | select a",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_record(record! {
|
||||
"a" => Value::test_string("a")
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"a" => Value::test_string("a")
|
||||
})])),
|
||||
},
|
||||
Example {
|
||||
description: "Select a field in a record",
|
||||
@ -151,7 +149,7 @@ produce a table, a list will produce a list, and a record will produce a record.
|
||||
"name" => Value::test_string("Cargo.lock"),
|
||||
"type" => Value::test_string("toml")
|
||||
}),
|
||||
]))
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Select multiple columns by spreading a list",
|
||||
@ -165,7 +163,7 @@ produce a table, a list will produce a list, and a record will produce a record.
|
||||
"name" => Value::test_string("Cargo.lock"),
|
||||
"type" => Value::test_string("toml")
|
||||
}),
|
||||
]))
|
||||
])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ impl Command for Skip {
|
||||
return Err(ShellError::TypeMismatch {
|
||||
err_message: "expected int".into(),
|
||||
span,
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -182,7 +182,7 @@ impl Command for Sort {
|
||||
Value::Nothing { .. } => {
|
||||
return Err(ShellError::PipelineEmpty {
|
||||
dst_span: value.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
ref other => {
|
||||
return Err(ShellError::OnlySupportsThisInputType {
|
||||
@ -190,7 +190,7 @@ impl Command for Sort {
|
||||
wrong_type: other.get_type().to_string(),
|
||||
dst_span: call.head,
|
||||
src_span: value.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(sorted.into_pipeline_data_with_metadata(metadata))
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
|
||||
use crate::Comparator;
|
||||
|
||||
@ -88,15 +88,15 @@ impl Command for SortBy {
|
||||
example: "[[name info]; [Cairo {founded: 969}] [Kyoto {founded: 794}]] | sort-by info.founded",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"name" => Value::test_string("Kyoto"),
|
||||
"info" => Value::test_record(
|
||||
record! { "founded" => Value::test_int(794) },
|
||||
)}),
|
||||
"name" => Value::test_string("Kyoto"),
|
||||
"info" => Value::test_record(
|
||||
record! { "founded" => Value::test_int(794) },
|
||||
)}),
|
||||
Value::test_record(record! {
|
||||
"name" => Value::test_string("Cairo"),
|
||||
"info" => Value::test_record(
|
||||
record! { "founded" => Value::test_int(969) },
|
||||
)})
|
||||
"name" => Value::test_string("Cairo"),
|
||||
"info" => Value::test_record(
|
||||
record! { "founded" => Value::test_int(969) },
|
||||
)}),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
@ -104,8 +104,8 @@ impl Command for SortBy {
|
||||
example: "[[2 50] [10 1]] | sort-by { last }",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_list(vec![Value::test_int(10), Value::test_int(1)]),
|
||||
Value::test_list(vec![Value::test_int(2), Value::test_int(50)])
|
||||
]))
|
||||
Value::test_list(vec![Value::test_int(2), Value::test_int(50)]),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Sort in a custom order",
|
||||
@ -116,8 +116,8 @@ impl Command for SortBy {
|
||||
Value::test_int(4),
|
||||
Value::test_int(7),
|
||||
Value::test_int(8),
|
||||
]))
|
||||
}
|
||||
])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ impl Command for SortBy {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{test_examples_with_commands, Last};
|
||||
use crate::{Last, test_examples_with_commands};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval};
|
||||
use nu_engine::{ClosureEval, command_prelude::*};
|
||||
use nu_protocol::engine::Closure;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -2,14 +2,14 @@ use nu_engine::{command_prelude::*, get_eval_block_with_early_return};
|
||||
#[cfg(feature = "os")]
|
||||
use nu_protocol::process::ChildPipe;
|
||||
use nu_protocol::{
|
||||
byte_stream::copy_with_signals, engine::Closure, report_shell_error, shell_error::io::IoError,
|
||||
ByteStream, ByteStreamSource, OutDest, PipelineMetadata, Signals,
|
||||
byte_stream::copy_with_signals, engine::Closure, report_shell_error, shell_error::io::IoError,
|
||||
};
|
||||
use std::{
|
||||
io::{self, Read, Write},
|
||||
sync::{
|
||||
mpsc::{self, Sender},
|
||||
Arc,
|
||||
mpsc::{self, Sender},
|
||||
},
|
||||
thread::{self, JoinHandle},
|
||||
};
|
||||
@ -55,8 +55,7 @@ use it in your pipeline."#
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
example:
|
||||
"nu -c 'print -e error; print ok' | tee --stderr { save error.log } | complete",
|
||||
example: "nu -c 'print -e error; print ok' | tee --stderr { save error.log } | complete",
|
||||
description: "Save error messages from an external command to a file without \
|
||||
redirecting them",
|
||||
result: None,
|
||||
@ -70,7 +69,7 @@ use it in your pipeline."#
|
||||
example: "10000 | tee { 1..$in | print } | $in * 5",
|
||||
description: "Do something with a value on another thread, while also passing through the value",
|
||||
result: Some(Value::test_int(50000)),
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@ -555,8 +554,8 @@ fn tee_forwards_errors_back_immediately() {
|
||||
#[test]
|
||||
fn tee_waits_for_the_other_thread() {
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
use std::time::Duration;
|
||||
let waited = Arc::new(AtomicBool::new(false));
|
||||
|
@ -106,8 +106,7 @@ impl Command for Transpose {
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description:
|
||||
"Transposes the table without column names and specify a new column name",
|
||||
description: "Transposes the table without column names and specify a new column name",
|
||||
example: "[[c1 c2]; [1 2]] | transpose --ignore-titles val",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
@ -180,7 +179,7 @@ pub fn transpose(
|
||||
for value in input.iter() {
|
||||
match value {
|
||||
Value::Error { .. } => {
|
||||
return Ok(value.clone().into_pipeline_data_with_metadata(metadata))
|
||||
return Ok(value.clone().into_pipeline_data_with_metadata(metadata));
|
||||
}
|
||||
Value::Record { .. } => {} // go on, this is what we're looking for
|
||||
_ => {
|
||||
@ -189,7 +188,7 @@ pub fn transpose(
|
||||
wrong_type: "list<any>".into(),
|
||||
dst_span: call.head,
|
||||
src_span: value.span(),
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use itertools::Itertools;
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::PipelineMetadata;
|
||||
use nu_utils::IgnoreCaseExt;
|
||||
use std::collections::{hash_map::IntoIter, HashMap};
|
||||
use std::collections::{HashMap, hash_map::IntoIter};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Uniq;
|
||||
@ -84,41 +84,34 @@ impl Command for Uniq {
|
||||
Example {
|
||||
description: "Return the input values that occur more than once",
|
||||
example: "[1 2 2] | uniq -d",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_int(2)],
|
||||
Span::test_data(),
|
||||
)),
|
||||
result: Some(Value::list(vec![Value::test_int(2)], Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Return the input values that occur once only",
|
||||
example: "[1 2 2] | uniq --unique",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_int(1)],
|
||||
Span::test_data(),
|
||||
)),
|
||||
result: Some(Value::list(vec![Value::test_int(1)], Span::test_data())),
|
||||
},
|
||||
Example {
|
||||
description: "Ignore differences in case when comparing input values",
|
||||
example: "['hello' 'goodbye' 'Hello'] | uniq --ignore-case",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_string("hello"), Value::test_string("goodbye")],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_string("hello"),
|
||||
Value::test_string("goodbye"),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Return a table containing the distinct input values together with their counts",
|
||||
example: "[1 2 2] | uniq --count",
|
||||
result: Some(Value::test_list(
|
||||
vec![
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(1),
|
||||
"count" => Value::test_int(1),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(2),
|
||||
"count" => Value::test_int(2),
|
||||
}),
|
||||
],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(1),
|
||||
"count" => Value::test_int(1),
|
||||
}),
|
||||
Value::test_record(record! {
|
||||
"value" => Value::test_int(2),
|
||||
"count" => Value::test_int(2),
|
||||
}),
|
||||
])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_engine::{command_prelude::*, ClosureEval, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEval, ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::ast::PathMember;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -67,36 +67,36 @@ When updating a specific index, the closure will instead be run once. The first
|
||||
Example {
|
||||
description: "Use a closure to alter each value in the 'authors' column to a single string",
|
||||
example: "[[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors {|row| $row.authors | str join ',' }",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_record(record! {
|
||||
"project" => Value::test_string("nu"),
|
||||
"authors" => Value::test_string("Andrés,JT,Yehuda"),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"project" => Value::test_string("nu"),
|
||||
"authors" => Value::test_string("Andrés,JT,Yehuda"),
|
||||
})])),
|
||||
},
|
||||
Example {
|
||||
description: "Implicitly use the `$in` value in a closure to update 'authors'",
|
||||
example: "[[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { str join ',' }",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_record(record! {
|
||||
"project" => Value::test_string("nu"),
|
||||
"authors" => Value::test_string("Andrés,JT,Yehuda"),
|
||||
})],
|
||||
)),
|
||||
result: Some(Value::test_list(vec![Value::test_record(record! {
|
||||
"project" => Value::test_string("nu"),
|
||||
"authors" => Value::test_string("Andrés,JT,Yehuda"),
|
||||
})])),
|
||||
},
|
||||
Example {
|
||||
description: "Update a value at an index in a list",
|
||||
example: "[1 2 3] | update 1 4",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_int(1), Value::test_int(4), Value::test_int(3)]
|
||||
)),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_int(1),
|
||||
Value::test_int(4),
|
||||
Value::test_int(3),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Use a closure to compute a new value at an index",
|
||||
example: "[1 2 3] | update 1 {|i| $i + 2 }",
|
||||
result: Some(Value::test_list(
|
||||
vec![Value::test_int(1), Value::test_int(4), Value::test_int(3)]
|
||||
)),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_int(1),
|
||||
Value::test_int(4),
|
||||
Value::test_int(3),
|
||||
])),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use nu_engine::{command_prelude::*, ClosureEval, ClosureEvalOnce};
|
||||
use nu_engine::{ClosureEval, ClosureEvalOnce, command_prelude::*};
|
||||
use nu_protocol::ast::PathMember;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user