forked from extern/nushell
Merge branch 'master' into surf
This commit is contained in:
commit
ac15989bbb
@ -1,6 +1,3 @@
|
||||
variables:
|
||||
lkg-rust-nightly: "2019-08-22"
|
||||
|
||||
trigger:
|
||||
- master
|
||||
|
||||
@ -8,13 +5,10 @@ strategy:
|
||||
matrix:
|
||||
linux-nightly:
|
||||
image: ubuntu-16.04
|
||||
toolchain: nightly-$(lkg-rust-nightly)
|
||||
macos-nightly:
|
||||
image: macos-10.14
|
||||
toolchain: nightly-$(lkg-rust-nightly)
|
||||
windows-nightly:
|
||||
image: vs2017-win2016
|
||||
toolchain: nightly-$(lkg-rust-nightly)
|
||||
|
||||
pool:
|
||||
vmImage: $(image)
|
||||
@ -22,10 +16,8 @@ pool:
|
||||
steps:
|
||||
- bash: |
|
||||
set -e
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain none
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain `cat rust-toolchain`
|
||||
export PATH=$HOME/.cargo/bin:$PATH
|
||||
rustup install --no-self-update $(toolchain)
|
||||
rustup default $(toolchain)
|
||||
rustc -Vv
|
||||
echo "##vso[task.prependpath]$HOME/.cargo/bin"
|
||||
displayName: Install Rust
|
||||
|
11
README.md
11
README.md
@ -18,11 +18,12 @@ There is also a [book](https://book.nushell.sh) about Nu, currently in progress.
|
||||
|
||||
Up-to-date installation instructions can be found in the [installation chapter of the book](https://book.nushell.sh/en/installation).
|
||||
|
||||
To build Nu, you will need to use the **nightly** version of the compiler.
|
||||
|
||||
Required dependencies:
|
||||
|
||||
* libssl
|
||||
* on macOS (via homebrew): `brew install openssl`
|
||||
* on Linux (on Debian/Ubuntu): `apt install libssl-dev`
|
||||
* libssl (only needed on Linux)
|
||||
* on Debian/Ubuntu: `apt install libssl-dev`
|
||||
|
||||
Optional dependencies:
|
||||
|
||||
@ -156,7 +157,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat
|
||||
|
||||
* Nu views data as both structured and unstructured. It is an object shell like PowerShell.
|
||||
|
||||
* Finally, Nu views data functionally. Rather than using mutation, pipelines act as a mean to load, change, and save data without mutable state.
|
||||
* Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means to load, change, and save data without mutable state.
|
||||
|
||||
# Commands
|
||||
## Initial commands
|
||||
@ -184,7 +185,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat
|
||||
| pick ...columns | Down-select table to only these columns |
|
||||
| reject ...columns | Remove the given columns from the table |
|
||||
| get column-or-column-path | Open given cells as text |
|
||||
| sort-by ...columns | Sort by the given columns |
|
||||
| sort-by ...columns (--reverse) | Sort by the given columns |
|
||||
| where condition | Filter table to match the condition |
|
||||
| inc (field) | Increment a value or version. Optional use the field of a table |
|
||||
| add field value | Add a new field to the table |
|
||||
|
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
@ -0,0 +1 @@
|
||||
nightly-2019-08-22
|
@ -168,6 +168,8 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||
whole_stream_command(SortBy),
|
||||
whole_stream_command(Tags),
|
||||
whole_stream_command(First),
|
||||
whole_stream_command(Last),
|
||||
whole_stream_command(FromArray),
|
||||
whole_stream_command(FromArray),
|
||||
whole_stream_command(FromCSV),
|
||||
whole_stream_command(FromINI),
|
||||
|
@ -22,6 +22,7 @@ crate mod from_toml;
|
||||
crate mod from_xml;
|
||||
crate mod from_yaml;
|
||||
crate mod get;
|
||||
crate mod last;
|
||||
crate mod lines;
|
||||
crate mod ls;
|
||||
crate mod mkdir;
|
||||
@ -76,6 +77,7 @@ crate use from_toml::FromTOML;
|
||||
crate use from_xml::FromXML;
|
||||
crate use from_yaml::FromYAML;
|
||||
crate use get::Get;
|
||||
crate use last::Last;
|
||||
crate use lines::Lines;
|
||||
crate use ls::LS;
|
||||
crate use mkdir::Mkdir;
|
||||
|
59
src/commands/last.rs
Normal file
59
src/commands/last.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use crate::commands::WholeStreamCommand;
|
||||
use crate::errors::ShellError;
|
||||
use crate::parser::CommandRegistry;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Last;
|
||||
|
||||
impl WholeStreamCommand for Last {
|
||||
fn run(
|
||||
&self,
|
||||
args: CommandArgs,
|
||||
registry: &CommandRegistry,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
last(args, registry)
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"last"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("last").required("amount", SyntaxType::Literal)
|
||||
}
|
||||
}
|
||||
|
||||
fn last(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once(registry)?;
|
||||
|
||||
let amount = args.expect_nth(0)?.as_i64();
|
||||
|
||||
let amount = match amount {
|
||||
Ok(o) => o,
|
||||
Err(_) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Value is not a number",
|
||||
"expected integer",
|
||||
args.expect_nth(0)?.span(),
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
if amount <= 0 {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Value is too low",
|
||||
"expected a positive integer",
|
||||
args.expect_nth(0)?.span(),
|
||||
))
|
||||
}
|
||||
|
||||
let stream = async_stream_block! {
|
||||
let v: Vec<_> = args.input.into_vec().await;
|
||||
let k = v.len() - (amount as usize);
|
||||
for x in v[k..].iter() {
|
||||
let y: Tagged<Value> = x.clone();
|
||||
yield ReturnSuccess::value(y)
|
||||
}
|
||||
};
|
||||
Ok(stream.to_output_stream())
|
||||
}
|
@ -18,7 +18,7 @@ impl WholeStreamCommand for SortBy {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("sort-by")
|
||||
Signature::build("sort-by").switch("reverse")
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,13 +37,21 @@ fn sort_by(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
|
||||
|
||||
let output = input.values.collect::<Vec<_>>();
|
||||
|
||||
let reverse = args.has("reverse");
|
||||
let output = output.map(move |mut vec| {
|
||||
vec.sort_by_key(|item| {
|
||||
let calc_key = |item: &Tagged<Value>| {
|
||||
fields
|
||||
.iter()
|
||||
.map(|f| item.get_data_by_key(f).map(|i| i.clone()))
|
||||
.collect::<Vec<Option<Tagged<Value>>>>()
|
||||
});
|
||||
};
|
||||
if reverse {
|
||||
vec.sort_by_cached_key(|item| {
|
||||
std::cmp::Reverse(calc_key(item))
|
||||
});
|
||||
} else {
|
||||
vec.sort_by_cached_key(calc_key);
|
||||
}
|
||||
|
||||
vec.into_iter().collect::<VecDeque<_>>()
|
||||
});
|
||||
|
@ -3,7 +3,6 @@
|
||||
#![feature(generators)]
|
||||
#![feature(try_trait)]
|
||||
#![feature(bind_by_move_pattern_guards)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(option_flattening)]
|
||||
#![feature(specialization)]
|
||||
#![feature(proc_macro_hygiene)]
|
||||
|
@ -4,7 +4,7 @@ use std::error::Error;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let matches = App::new("nushell")
|
||||
.version("0.1.3")
|
||||
.version(clap::crate_version!())
|
||||
.arg(
|
||||
Arg::with_name("loglevel")
|
||||
.short("l")
|
||||
|
@ -14,7 +14,7 @@ pub trait ExtractType: Sized {
|
||||
|
||||
impl<T> ExtractType for T {
|
||||
default fn extract(_value: &Tagged<Value>) -> Result<T, ShellError> {
|
||||
let name = std::intrinsics::type_name::<T>();
|
||||
let name = std::any::type_name::<T>();
|
||||
Err(ShellError::unimplemented(format!(
|
||||
"<T> ExtractType for {}",
|
||||
name
|
||||
@ -32,7 +32,7 @@ impl<T> ExtractType for T {
|
||||
|
||||
impl<T: ExtractType> ExtractType for Vec<Tagged<T>> {
|
||||
fn extract(value: &Tagged<Value>) -> Result<Self, ShellError> {
|
||||
let name = std::intrinsics::type_name::<T>();
|
||||
let name = std::any::type_name::<T>();
|
||||
trace!("<Vec> Extracting {:?} for Vec<{}>", value, name);
|
||||
|
||||
match value.item() {
|
||||
@ -69,8 +69,8 @@ impl<T: ExtractType> ExtractType for Vec<Tagged<T>> {
|
||||
|
||||
impl<T: ExtractType, U: ExtractType> ExtractType for (T, U) {
|
||||
fn extract(value: &Tagged<Value>) -> Result<(T, U), ShellError> {
|
||||
let t_name = std::intrinsics::type_name::<T>();
|
||||
let u_name = std::intrinsics::type_name::<U>();
|
||||
let t_name = std::any::type_name::<T>();
|
||||
let u_name = std::any::type_name::<U>();
|
||||
|
||||
trace!("Extracting {:?} for ({}, {})", value, t_name, u_name);
|
||||
|
||||
@ -98,7 +98,7 @@ impl<T: ExtractType, U: ExtractType> ExtractType for (T, U) {
|
||||
|
||||
impl<T: ExtractType> ExtractType for Option<T> {
|
||||
fn extract(value: &Tagged<Value>) -> Result<Option<T>, ShellError> {
|
||||
let name = std::intrinsics::type_name::<T>();
|
||||
let name = std::any::type_name::<T>();
|
||||
trace!("<Option> Extracting {:?} for Option<{}>", value, name);
|
||||
|
||||
let result = match value.item() {
|
||||
@ -123,7 +123,7 @@ impl<T: ExtractType> ExtractType for Option<T> {
|
||||
|
||||
impl<T: ExtractType> ExtractType for Tagged<T> {
|
||||
fn extract(value: &Tagged<Value>) -> Result<Tagged<T>, ShellError> {
|
||||
let name = std::intrinsics::type_name::<T>();
|
||||
let name = std::any::type_name::<T>();
|
||||
trace!("<Tagged> Extracting {:?} for Tagged<{}>", value, name);
|
||||
|
||||
Ok(T::extract(value)?.tagged(value.tag()))
|
||||
|
@ -70,7 +70,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
let value = self.pop();
|
||||
let name = std::intrinsics::type_name::<V::Value>();
|
||||
let name = std::any::type_name::<V::Value>();
|
||||
trace!("<Deserialize any> Extracting {:?}", name);
|
||||
|
||||
V::Value::extract(&value.val)
|
||||
@ -237,7 +237,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
|
||||
|
||||
if self.saw_root {
|
||||
let value = self.pop();
|
||||
let name = std::intrinsics::type_name::<V::Value>();
|
||||
let name = std::any::type_name::<V::Value>();
|
||||
trace!("Extracting {:?} for {:?}", value.val, name);
|
||||
V::Value::extract(&value.val)
|
||||
} else {
|
||||
|
@ -57,6 +57,17 @@ fn can_sort_by_column() {
|
||||
assert_eq!(output, "description");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_sort_by_column_reverse() {
|
||||
nu!(
|
||||
output,
|
||||
cwd("tests/fixtures/formats"),
|
||||
"open cargo_sample.toml --raw | lines | skip 1 | first 4 | split-column \"=\" | sort-by Column1 --reverse | skip 1 | first 1 | get Column1 | trim | echo $it"
|
||||
);
|
||||
|
||||
assert_eq!(output, "name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_split_by_column() {
|
||||
nu!(
|
||||
@ -89,3 +100,14 @@ fn can_filter_by_unit_size_comparison() {
|
||||
|
||||
assert_eq!(output, "caco3_plastics.csv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_get_last() {
|
||||
nu!(
|
||||
output,
|
||||
cwd("tests/fixtures/formats"),
|
||||
"ls | sort-by name | last 1 | get name | trim | echo $it"
|
||||
);
|
||||
|
||||
assert_eq!(output, "utf16.ini");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user