Compare commits

...

53 Commits

Author SHA1 Message Date
7dc1d6a350 Extract .nu-env tests and more granularity (#3078)
The autoenv logic mutates environment variables in the running session as
it operates and decides what to do for trusted directories containing `.nu-env`
files. Few of the ways to interact with it were all in a single test function.

We separate out all the ways that were done in the single test function to document
 it better. This will greatly help once we start refactoring our way out from setting
 environment variables this way to just setting them to `Scope`.

This is part of an on-going effort to keep variables (`PATH` and `ENV`)
in our `Scope` and rely on it for everything related to variables.

We expect to move away from setting (`std::*`) envrironment variables in the current
running process. This is non-trivial since we need to handle cases from vars
coming in from the outside world, prioritize, and also compare to the ones
we have both stored in memory and in configuration files.

Also to send out our in-memory (in `Scope`) variables properly to external
programs once we no longer rely on `std::env` vars from the running process.
2021-02-18 20:24:27 -05:00
deff1aa63b Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
08e7d0dfb6 Keep the environment properly set. (#3072)
* Revert "fix prompts on startup (#3056)"

This reverts commit b202951c1d.

* Ensure environment variables synced with global internal Nu Scope.
2021-02-18 15:56:14 +13:00
892aae267d add height method to Host trait, and implementors (#3064) 2021-02-17 09:02:13 +13:00
11a9144e84 update mock table for easier table testing (#3065) 2021-02-17 04:47:47 +13:00
039f223b53 Bump to 0.27 (#3063) 2021-02-16 19:20:05 +13:00
e1cb026184 Add back in column truncation (#3061) 2021-02-16 07:15:16 +13:00
2a96152a43 fix sample_config: date --format no longer supported (#3060)
Co-authored-by: alexhk <alexhk@protonmail.com>
2021-02-15 10:24:55 -06:00
0795d56c1c Source path including tilda (#3059)
* Use expand_path to handle the path including tilda

* Publish path::expand_path for using in nu-command

* cargo fmt

Co-authored-by: Wataru Yamaguchi <nagisamark2@gmail.com>
2021-02-15 21:41:49 +13:00
48a90fea70 Fix let-env (#3057) 2021-02-15 20:58:51 +13:00
b202951c1d fix prompts on startup (#3056)
* fix prompts on startup

* Try again
2021-02-15 20:14:16 +13:00
c3d2c61729 nu-parser: fix parsing comments with unclosed ' " [] {} in functions (#3053)
* nu-parser: fix parsing comments with unclosed ' " [] {} in functions

* add tests for last commit
2021-02-14 21:40:28 +13:00
d7b707939f Fix quick command reference link in README (#3052) 2021-02-14 18:38:01 +13:00
991ac6eb77 change help text (#3054) 2021-02-13 13:20:34 -06:00
011b7c4a07 refactor parser: rename method pub fn block to parse_block (#3047)
* refactor parser: rename method block to parse_block

* nu-cli/src/completion/engine.rs block to parse_block
2021-02-13 09:31:11 +13:00
617341f8d5 nu-engine: deserialize_struct: fix missing conversion from string to column path (#3048) 2021-02-13 09:29:38 +13:00
abd2632977 Remove accidental debug symbols in release (#3050) 2021-02-13 09:28:41 +13:00
5481db4079 Fix latest clippy warnings (#3049) 2021-02-12 23:13:14 +13:00
041086d22a add config "filesize_metric = true" for default formatting of filesize (#3045) 2021-02-11 21:52:34 +13:00
aa564f5072 display boolean config options as true/false instead of Yes/No (#3043) 2021-02-11 21:50:33 +13:00
8367f2001c update nuver (#3044) 2021-02-10 08:58:38 -06:00
1cfb228924 New termsize command (#3038)
* add term size command

* update w & h, add examples

* changed default to output table
2021-02-10 08:58:22 -06:00
b403fb1275 nu-parser + nu-protocol: switch to metric for KB, MB, GB, add KiB, MiB, GiB units (#3035)
fixes inconsistency with formatting/rendering which uses standard Rust byte_unit
https://en.wikipedia.org/wiki/Byte#Multiple-byte_units
2021-02-10 15:31:12 +13:00
3443ca40c5 updated a few items (#3040) 2021-02-09 17:11:36 -06:00
96f95653a6 added comment for table_mode (#3036) 2021-02-09 09:06:30 -06:00
7f7e8465da Fix fmt and small cleaning in nu-parser (#3033)
* parse_unit: reduce indentation in loop

* fix fmt: crates/nu-parser/src/lex/tests.rs
2021-02-09 17:46:10 +13:00
e3a273cf73 Update config (#3031) 2021-02-09 17:44:42 +13:00
233161d56e sort_by: support -r flag for reverse (#3025)
* sort_by: support -r flag for reverse

* Update sort_by.rs

Fix reverse test

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2021-02-08 11:10:06 +13:00
d883ab250a which: accept several applications/commands (#3024)
* which: accept several applications

* fix fmt: which_.rs
2021-02-08 08:17:06 +13:00
ef4e3f907c parser/refactor def (#2986)
* Move tests into own file

* Move data structs to own file

* Move functions parsing 1 Token (primitives) into own file

* Rename param_flag_list to signature

* Add tests

* Fix clippy lint

* Change imports to new lexer structure
2021-02-08 08:10:14 +13:00
debeadbf3f Soft rest arguments column path cohersions. (#3016) 2021-02-06 20:05:47 -05:00
d66baaceb9 Fix 'ps -l' output when a process doesn't have a parent process. (#3015)
Before, ps would not insert a value if the process didn't have a parent.
Now, ps will insert an empty cell. This caused broken tables as some
rows didn't have all the columns.
2021-02-06 22:41:08 +13:00
85329f9a81 Fix readme (#3013) 2021-02-06 14:18:38 +13:00
a5fefaf78b Ensure selection of columns are done once per column (#3012) 2021-02-05 19:34:26 -05:00
6f17662a4e Update some deps (#3011) 2021-02-06 09:54:54 +13:00
c83aea3c89 Bump to 0.26.1 (#3008) 2021-02-05 19:38:04 +13:00
67aaf4cb2d fix the ps command's virtual mem (#3007) 2021-02-05 18:57:49 +13:00
3083346884 update sysinfo to v16 (#3006) 2021-02-05 06:59:24 +13:00
d07789677f Clean up lexer (#2956)
* Document the lexer and lightly improve its names

The bulk of this pull request adds a substantial amount of new inline
documentation for the lexer. Along the way, I made a few minor changes
to the names in the lexer, most of which were internal.

The main change that affects other files is renaming `group` to `block`,
since the function is actually parsing a block (a list of groups).

* Further clean up the lexer

- Consolidate the logic of the various token builders into a single type
- Improve and clean up the event-driven BlockParser
- Clean up comment parsing. Comments now contain their original leading
  whitespace as well as trailing whitespace, and know how to move some
  leading whitespace back into the body based on how the lexer decides
  to dedent the comments. This preserves the original whitespace
  information while still making it straight-forward to eliminate leading
  whitespace in help comments.

* Update meta.rs

* WIP

* fix clippy

* remove unwraps

* remove unwraps

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Jonathan Turner <jonathan.d.turner@gmail.com>
2021-02-04 20:20:21 +13:00
fb1846120d standardize on how to get file size (#2992)
* standardize on how to get file size

* forgot to remove comment

* make specified size lowercase

* fix the test due to precision

* added another test

* Update README.md

add contributors graphic

* clippy - test adjustment

* tweaked matching
2021-02-03 07:19:38 -06:00
da1e1295ea Update README.md 2021-02-03 15:08:18 +13:00
ecaea57263 Value helpers (#3000)
* Update README.md

add contributors graphic

* just a couple of helpers

* separated some helpers out to individual fns
2021-02-03 15:06:11 +13:00
fa928bd25d Minimal markdown syntax per element support. (#2997) 2021-02-02 12:09:19 -05:00
c1981dfc26 Fix README formatting (#2996) 2021-02-02 19:23:38 +13:00
fd41fa31d5 add $nothing and tests (#2995) 2021-02-02 19:23:12 +13:00
2c52144f41 Update README.md (#2993)
add contributors graphic
2021-02-02 07:05:37 +13:00
87c7898b65 update sysinfo due to breaking change with get_version (#2988) 2021-01-30 12:21:32 -06:00
44e088c6fe Move filesize to use bigint (#2984)
* Move filesize to be bigint-sized

* Add tests and fix filesize display

* clippy
2021-01-30 11:35:18 +13:00
7b4cbd7ce9 Few fixes for WASI build (#2983)
- Disable shadow-rs (libgit2-sys compilation on WASI fails for various strange reasons, so seems easier to disable altogether for now).
 - Disable directories-support (WASI doesn't have concept of user directory and such calls fail at runtime).
2021-01-30 09:11:07 +13:00
b052d524da added pow operator, and filesize math (#2976)
* added pow operator, and filesize math

* removed + and - arms, removed some pow, pow higher precedence

* Update value.rs

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2021-01-29 07:44:02 -06:00
47c4b8e88a allow str from to convert more things to string (#2977)
* allow str from to convert more things to string

* fixed FileSize so it reports with units configured

* added tests
2021-01-29 07:43:35 -06:00
d0a2a02eea Add possibility to declare optional parameters and switch flags (#2966)
* Add possibility to declare optional parameters and switch flags

With this commit applied it is now possible to specify optional parameters and flags
as switches. This PR **only** makes guarantees about **parsing** optional flags and
switches correctly. This PR **does not guarantee flawless functionality** of
optional parameters / switches within scripts.
functionality within scripts. Example:

test.nu
```shell
def my_command [
    opt_param?
    opt_param2?: int
    --switch
] {echo hi nushell}
```

```shell
> source test.nu
> my_command -h
───┬─────────
 0 │ hi
 1 │ nushell
───┴─────────
Usage:
  > my_command <mandatory_param> (opt_param) (opt_param2) {flags}

Parameters:
  <mandatory_param>
  (opt_param)
  (opt_param2)

Flags:
  -h, --help: Display this help message
  --switch
  --opt_flag <any>
```

* Update def docs
2021-01-28 06:31:29 +13:00
b1e1dab4cb add % operator for modulus, work with decimals (#2975)
* add % operator, work with decimals

* removed the % operator to reserve for something else
2021-01-26 12:42:34 -06:00
332 changed files with 6113 additions and 4245 deletions

561
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ license = "MIT"
name = "nu"
readme = "README.md"
repository = "https://github.com/nushell/nushell"
version = "0.26.0"
version = "0.27.1"
[workspace]
members = ["crates/*/"]
@ -18,80 +18,110 @@ members = ["crates/*/"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nu-cli = {version = "0.26.0", path = "./crates/nu-cli"}
nu-command = {version = "0.26.0", path = "./crates/nu-command"}
nu-data = {version = "0.26.0", path = "./crates/nu-data"}
nu-engine = {version = "0.26.0", path = "./crates/nu-engine"}
nu-errors = {version = "0.26.0", path = "./crates/nu-errors"}
nu-parser = {version = "0.26.0", path = "./crates/nu-parser"}
nu-plugin = {version = "0.26.0", path = "./crates/nu-plugin"}
nu-protocol = {version = "0.26.0", path = "./crates/nu-protocol"}
nu-source = {version = "0.26.0", path = "./crates/nu-source"}
nu-value-ext = {version = "0.26.0", path = "./crates/nu-value-ext"}
nu-cli = { version = "0.27.1", path = "./crates/nu-cli", default-features = false }
nu-command = { version = "0.27.1", path = "./crates/nu-command" }
nu-data = { version = "0.27.1", path = "./crates/nu-data" }
nu-engine = { version = "0.27.1", path = "./crates/nu-engine" }
nu-errors = { version = "0.27.1", path = "./crates/nu-errors" }
nu-parser = { version = "0.27.1", path = "./crates/nu-parser" }
nu-plugin = { version = "0.27.1", path = "./crates/nu-plugin" }
nu-protocol = { version = "0.27.1", path = "./crates/nu-protocol" }
nu-source = { version = "0.27.1", path = "./crates/nu-source" }
nu-value-ext = { version = "0.27.1", path = "./crates/nu-value-ext" }
nu_plugin_binaryview = {version = "0.26.0", path = "./crates/nu_plugin_binaryview", optional = true}
nu_plugin_chart = {version = "0.26.0", path = "./crates/nu_plugin_chart", optional = true}
nu_plugin_fetch = {version = "0.26.0", path = "./crates/nu_plugin_fetch", optional = true}
nu_plugin_from_bson = {version = "0.26.0", path = "./crates/nu_plugin_from_bson", optional = true}
nu_plugin_from_sqlite = {version = "0.26.0", path = "./crates/nu_plugin_from_sqlite", optional = true}
nu_plugin_inc = {version = "0.26.0", path = "./crates/nu_plugin_inc", optional = true}
nu_plugin_match = {version = "0.26.0", path = "./crates/nu_plugin_match", optional = true}
nu_plugin_post = {version = "0.26.0", path = "./crates/nu_plugin_post", optional = true}
nu_plugin_ps = {version = "0.26.0", path = "./crates/nu_plugin_ps", optional = true}
nu_plugin_s3 = {version = "0.26.0", path = "./crates/nu_plugin_s3", optional = true}
nu_plugin_selector = {version = "0.26.0", path = "./crates/nu_plugin_selector", optional = true}
nu_plugin_start = {version = "0.26.0", path = "./crates/nu_plugin_start", optional = true}
nu_plugin_sys = {version = "0.26.0", path = "./crates/nu_plugin_sys", optional = true}
nu_plugin_textview = {version = "0.26.0", path = "./crates/nu_plugin_textview", optional = true}
nu_plugin_to_bson = {version = "0.26.0", path = "./crates/nu_plugin_to_bson", optional = true}
nu_plugin_to_sqlite = {version = "0.26.0", path = "./crates/nu_plugin_to_sqlite", optional = true}
nu_plugin_tree = {version = "0.26.0", path = "./crates/nu_plugin_tree", optional = true}
nu_plugin_xpath = {version = "0.26.0", path = "./crates/nu_plugin_xpath", optional = true}
nu_plugin_binaryview = { version = "0.27.1", path = "./crates/nu_plugin_binaryview", optional = true }
nu_plugin_chart = { version = "0.27.1", path = "./crates/nu_plugin_chart", optional = true }
nu_plugin_fetch = { version = "0.27.1", path = "./crates/nu_plugin_fetch", optional = true }
nu_plugin_from_bson = { version = "0.27.1", path = "./crates/nu_plugin_from_bson", optional = true }
nu_plugin_from_sqlite = { version = "0.27.1", path = "./crates/nu_plugin_from_sqlite", optional = true }
nu_plugin_inc = { version = "0.27.1", path = "./crates/nu_plugin_inc", optional = true }
nu_plugin_match = { version = "0.27.1", path = "./crates/nu_plugin_match", optional = true }
nu_plugin_post = { version = "0.27.1", path = "./crates/nu_plugin_post", optional = true }
nu_plugin_ps = { version = "0.27.1", path = "./crates/nu_plugin_ps", optional = true }
nu_plugin_s3 = { version = "0.27.1", path = "./crates/nu_plugin_s3", optional = true }
nu_plugin_selector = { version = "0.27.1", path = "./crates/nu_plugin_selector", optional = true }
nu_plugin_start = { version = "0.27.1", path = "./crates/nu_plugin_start", optional = true }
nu_plugin_sys = { version = "0.27.1", path = "./crates/nu_plugin_sys", optional = true }
nu_plugin_textview = { version = "0.27.1", path = "./crates/nu_plugin_textview", optional = true }
nu_plugin_to_bson = { version = "0.27.1", path = "./crates/nu_plugin_to_bson", optional = true }
nu_plugin_to_sqlite = { version = "0.27.1", path = "./crates/nu_plugin_to_sqlite", optional = true }
nu_plugin_tree = { version = "0.27.1", path = "./crates/nu_plugin_tree", optional = true }
nu_plugin_xpath = { version = "0.27.1", path = "./crates/nu_plugin_xpath", optional = true }
# Required to bootstrap the main binary
clap = "2.33.3"
ctrlc = {version = "3.1.6", optional = true}
futures = {version = "0.3.5", features = ["compat", "io-compat"]}
ctrlc = { version = "3.1.7", optional = true }
futures = { version = "0.3.12", features = ["compat", "io-compat"] }
itertools = "0.10.0"
log = "0.4.11"
log = "0.4.14"
pretty_env_logger = "0.4.0"
[dev-dependencies]
nu-test-support = { version = "0.27.1", path = "./crates/nu-test-support" }
dunce = "1.0.1"
nu-test-support = {version = "0.26.0", path = "./crates/nu-test-support"}
serial_test = "0.5.1"
[build-dependencies]
[features]
ctrlc-support = ["nu-cli/ctrlc", "nu-command/ctrlc"]
directories-support = ["nu-cli/directories", "nu-cli/dirs", "nu-command/directories", "nu-command/dirs", "nu-data/directories", "nu-data/dirs", "nu-engine/dirs"]
directories-support = [
"nu-cli/directories",
"nu-cli/dirs",
"nu-command/directories",
"nu-command/dirs",
"nu-data/directories",
"nu-data/dirs",
"nu-engine/dirs",
]
ptree-support = ["nu-cli/ptree", "nu-command/ptree"]
rustyline-support = ["nu-cli/rustyline-support", "nu-command/rustyline-support"]
term-support = ["nu-cli/term", "nu-command/term"]
uuid-support = ["nu-cli/uuid_crate", "nu-command/uuid_crate"]
which-support = ["nu-cli/ichwh", "nu-cli/which", "nu-command/ichwh", "nu-command/which"]
which-support = [
"nu-cli/ichwh",
"nu-cli/which",
"nu-command/ichwh",
"nu-command/which",
]
default = [
"sys",
"ps",
"textview",
"inc",
"directories-support",
"ctrlc-support",
"which-support",
"ptree-support",
"term-support",
"uuid-support",
"rustyline-support",
"match",
"post",
"fetch",
"zip-support",
"nu-cli/shadow-rs",
"sys",
"ps",
"textview",
"inc",
"directories-support",
"ctrlc-support",
"which-support",
"ptree-support",
"term-support",
"uuid-support",
"rustyline-support",
"match",
"post",
"fetch",
"zip-support",
]
extra = ["default", "binaryview", "tree", "clipboard-cli", "trash-support", "start", "bson", "sqlite", "s3", "chart", "xpath", "selector"]
stable = ["default"]
wasi = ["inc", "match", "directories-support", "ptree-support", "match", "tree", "rustyline-support"]
stable = ["default"]
extra = [
"default",
"binaryview",
"tree",
"clipboard-cli",
"trash-support",
"start",
"bson",
"sqlite",
"s3",
"chart",
"xpath",
"selector",
]
wasi = ["inc", "match", "ptree-support", "match", "tree", "rustyline-support"]
trace = ["nu-parser/trace"]

View File

@ -44,19 +44,19 @@ Try it in Gitpod.
### Local
Up-to-date installation instructions can be found in the [installation chapter of the book](https://www.nushell.sh/book/installation.html). **Windows users**: please note that Nu works on Windows 10 and does not currently have Windows 7/8.1 support.
Up-to-date installation instructions can be found in the [installation chapter of the book](https://www.nushell.sh/book/installation.html). **Windows users**: please note that Nu works on Windows 10 and does not currently have Windows 7/8.1 support.
To build Nu, you will need to use the **latest stable (1.47 or later)** version of the compiler.
Required dependencies:
* pkg-config and libssl (only needed on Linux)
* On Debian/Ubuntu: `apt install pkg-config libssl-dev`
- pkg-config and libssl (only needed on Linux)
- On Debian/Ubuntu: `apt install pkg-config libssl-dev`
Optional dependencies:
* To use Nu with all possible optional features enabled, you'll also need the following:
* On Linux (on Debian/Ubuntu): `apt install libxcb-composite0-dev libx11-dev`
- To use Nu with all possible optional features enabled, you'll also need the following:
- On Linux (on Debian/Ubuntu): `apt install libxcb-composite0-dev libx11-dev`
To install Nu via cargo (make sure you have installed [rustup](https://rustup.rs/) and the latest stable compiler via `rustup install stable`):
@ -139,9 +139,9 @@ Just as the Unix philosophy, Nu allows commands to output from stdout and read f
Additionally, commands can output structured data (you can think of this as a third kind of stream).
Commands that work in the pipeline fit into one of three categories:
* Commands that produce a stream (eg, `ls`)
* Commands that filter a stream (eg, `where type == "Dir"`)
* Commands that consume the output of the pipeline (eg, `autoview`)
- Commands that produce a stream (eg, `ls`)
- Commands that filter a stream (eg, `where type == "Dir"`)
- Commands that consume the output of the pipeline (eg, `autoview`)
Commands are separated by the pipe symbol (`|`) to denote a pipeline flowing left to right.
@ -270,40 +270,40 @@ If the plugin is a sink, it is given the full vector of final data and is given
Nu adheres closely to a set of goals that make up its design philosophy. As features are added, they are checked against these goals.
* First and foremost, Nu is cross-platform. Commands and techniques should carry between platforms and offer first-class consistent support for Windows, macOS, and Linux.
- First and foremost, Nu is cross-platform. Commands and techniques should carry between platforms and offer first-class consistent support for Windows, macOS, and Linux.
* Nu ensures direct compatibility with existing platform-specific executables that make up people's workflows.
- Nu ensures direct compatibility with existing platform-specific executables that make up people's workflows.
* Nu's workflow and tools should have the usability in day-to-day experience of using a shell in 2019 (and beyond).
- Nu's workflow and tools should have the usability in day-to-day experience of using a shell in 2019 (and beyond).
* Nu views data as both structured and unstructured. It is a structured shell like PowerShell.
- Nu views data as both structured and unstructured. It is a structured shell like PowerShell.
* Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means 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
You can find a list of Nu commands, complete with documentation, in [quick command references](https://www.nushell.sh/documentation.html#quick-command-references).
You can find a list of Nu commands, complete with documentation, in [quick command references](https://www.nushell.sh/book/command_reference.html).
## Progress
Nu is in heavy development, and will naturally change as it matures and people use it. The chart below isn't meant to be exhaustive, but rather helps give an idea for some of the areas of development and their relative completion:
Nu is in heavy development, and will naturally change as it matures and people use it. The chart below isn't meant to be exhaustive, but rather helps give an idea for some of the areas of development and their relative completion:
| Features | Not started | Prototype | MVP | Preview | Mature | Notes
| -------- |:-----------:|:---------:|:---:|:-------:|:------:| -----
| Aliases | | X | | | | Initial implementation but lacks necessary features
| Notebook | | X | | | | Initial jupyter support, but it loses state and lacks features
| File ops | | | X | | | cp, mv, rm, mkdir have some support, but lacking others
| Environment | | X | | | | Temporary environment, but no session-wide env variables
| Shells | | X | | | | Basic value and file shells, but no opt-in/opt-out for commands
| Protocol | | | X | | | Streaming protocol is serviceable
| Plugins | | X | | | | Plugins work on one row at a time, lack batching and expression eval
| Errors | | | X | | | Error reporting works, but could use usability polish
| Documentation | | X | | | | Book and related are barebones and lack task-based lessons
| Paging | | X | | | | Textview has paging, but we'd like paging for tables
| Functions | | X | | | | No functions, yet, only aliases
| Variables| | X | | | | Nu doesn't yet support variables
| Completions | | X | | | | Completions are currently barebones, at best
| Type-checking | | X | | | | Commands check basic types, but input/output isn't checked
| Features | Not started | Prototype | MVP | Preview | Mature | Notes |
| ------------- | :---------: | :-------: | :-: | :-----: | :----: | -------------------------------------------------------------------- |
| Aliases | | X | | | | Initial implementation but lacks necessary features |
| Notebook | | X | | | | Initial jupyter support, but it loses state and lacks features |
| File ops | | | X | | | cp, mv, rm, mkdir have some support, but lacking others |
| Environment | | X | | | | Temporary environment, but no session-wide env variables |
| Shells | | X | | | | Basic value and file shells, but no opt-in/opt-out for commands |
| Protocol | | | X | | | Streaming protocol is serviceable |
| Plugins | | X | | | | Plugins work on one row at a time, lack batching and expression eval |
| Errors | | | X | | | Error reporting works, but could use usability polish |
| Documentation | | X | | | | Book and related are barebones and lack task-based lessons |
| Paging | | X | | | | Textview has paging, but we'd like paging for tables |
| Functions | | X | | | | No functions, yet, only aliases |
| Variables | | X | | | | Nu doesn't yet support variables |
| Completions | | X | | | | Completions are currently barebones, at best |
| Type-checking | | X | | | | Commands check basic types, but input/output isn't checked |
## Current Roadmap
@ -313,6 +313,12 @@ We've added a `Roadmap Board` to help collaboratively capture the direction we'r
See [Contributing](CONTRIBUTING.md) for details.
Thanks to all the people who already contributed!
<a href="https://github.com/nushell/nushell/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=nushell/nushell" />
</a>
## License
The project is made available under the MIT license. See the `LICENSE` file for more information.

View File

@ -5,107 +5,107 @@ description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-cli"
version = "0.26.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-command = { version = "0.26.0", path = "../nu-command" }
nu-data = { version = "0.26.0", path = "../nu-data" }
nu-engine = { version = "0.26.0", path = "../nu-engine" }
nu-errors = { version = "0.26.0", path = "../nu-errors" }
nu-json = { version = "0.26.0", path = "../nu-json" }
nu-parser = { version = "0.26.0", path = "../nu-parser" }
nu-plugin = { version = "0.26.0", path = "../nu-plugin" }
nu-protocol = { version = "0.26.0", path = "../nu-protocol" }
nu-source = { version = "0.26.0", path = "../nu-source" }
nu-stream = { version = "0.26.0", path = "../nu-stream" }
nu-table = { version = "0.26.0", path = "../nu-table" }
nu-test-support = { version = "0.26.0", path = "../nu-test-support" }
nu-value-ext = { version = "0.26.0", path = "../nu-value-ext" }
nu-command = { version = "0.27.1", path = "../nu-command" }
nu-data = { version = "0.27.1", path = "../nu-data" }
nu-engine = { version = "0.27.1", path = "../nu-engine" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-json = { version = "0.27.1", path = "../nu-json" }
nu-parser = { version = "0.27.1", path = "../nu-parser" }
nu-plugin = { version = "0.27.1", path = "../nu-plugin" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-stream = { version = "0.27.1", path = "../nu-stream" }
nu-table = { version = "0.27.1", path = "../nu-table" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
Inflector = "0.11"
ansi_term = "0.12.1"
arboard = { version = "1.1.0", optional = true }
async-recursion = "0.3.1"
async-trait = "0.1.40"
async-recursion = "0.3.2"
async-trait = "0.1.42"
base64 = "0.13.0"
bigdecimal = { version = "0.2.0", features = ["serde"] }
byte-unit = "4.0.9"
bytes = "0.5.6"
calamine = "0.16.1"
chrono = { version = "0.4.15", features = ["serde"] }
bytes = "1.0.1"
calamine = "0.17.0"
chrono = { version = "0.4.19", features = ["serde"] }
chrono-tz = "0.5.3"
clap = "2.33.3"
codespan-reporting = "0.11.0"
csv = "1.1.3"
ctrlc = { version = "3.1.6", optional = true }
csv = "1.1.5"
ctrlc = { version = "3.1.7", optional = true }
derive-new = "0.5.8"
directories-next = { version = "2.0.0", optional = true }
dirs-next = { version = "2.0.0", optional = true }
dtparse = "1.2.0"
dunce = "1.0.1"
eml-parser = "0.1.0"
encoding_rs = "0.8.24"
encoding_rs = "0.8.28"
filesize = "0.2.0"
fs_extra = "1.2.0"
futures = { version = "0.3.5", features = ["compat", "io-compat"] }
futures-util = "0.3.8"
futures = { version = "0.3.12", features = ["compat", "io-compat"] }
futures-util = "0.3.12"
futures_codec = "0.4.1"
getset = "0.1.1"
glob = "0.3.0"
htmlescape = "0.3.1"
ical = "0.7.0"
ichwh = { version = "0.3.4", optional = true }
indexmap = { version = "1.6.0", features = ["serde-1"] }
indexmap = { version = "1.6.1", features = ["serde-1"] }
itertools = "0.10.0"
lazy_static = "1.*"
log = "0.4.11"
log = "0.4.14"
meval = "0.2.0"
num-bigint = { version = "0.3.0", features = ["serde"] }
num-bigint = { version = "0.3.1", features = ["serde"] }
num-format = { version = "0.4.0", features = ["with-num-bigint"] }
num-traits = "0.2.12"
parking_lot = "0.11.0"
num-traits = "0.2.14"
parking_lot = "0.11.1"
pin-utils = "0.1.0"
pretty-hex = "0.2.0"
ptree = { version = "0.3.0", optional = true }
pretty-hex = "0.2.1"
ptree = { version = "0.3.1", optional = true }
query_interface = "0.3.5"
quick-xml = "0.20.0"
rand = "0.7.3"
rayon = "1.4.0"
regex = "1.3.9"
quick-xml = "0.21.0"
rand = "0.8.3"
rayon = "1.5.0"
regex = "1.4.3"
roxmltree = "0.14.0"
rust-embed = "5.8.0"
rust-embed = "5.9.0"
rustyline = { version = "6.3.0", optional = true }
serde = { version = "1.0.115", features = ["derive"] }
serde = { version = "1.0.123", features = ["derive"] }
serde_bytes = "0.11.5"
serde_ini = "0.2.0"
serde_json = "1.0.57"
serde_json = "1.0.61"
serde_urlencoded = "0.7.0"
serde_yaml = "0.8.13"
sha2 = "0.9.1"
shellexpand = "2.0.0"
serde_yaml = "0.8.16"
sha2 = "0.9.3"
shellexpand = "2.1.0"
strip-ansi-escapes = "0.1.0"
sxd-document = "0.3.2"
sxd-xpath = "0.4.2"
tempfile = "3.1.0"
term = { version = "0.6.1", optional = true }
tempfile = "3.2.0"
term = { version = "0.7.0", optional = true }
term_size = "0.3.2"
termcolor = "1.1.0"
titlecase = "1.0"
toml = "0.5.6"
trash = { version = "1.2.0", optional = true }
unicode-segmentation = "1.6.0"
termcolor = "1.1.2"
titlecase = "1.1.0"
toml = "0.5.8"
trash = { version = "1.3.0", optional = true }
unicode-segmentation = "1.7.1"
url = "2.1.1"
uuid_crate = { package = "uuid", version = "0.8.1", features = ["v4"], optional = true }
uuid_crate = { package = "uuid", version = "0.8.2", features = ["v4"], optional = true }
which = { version = "4.0.2", optional = true }
zip = { version = "0.5.7", optional = true }
zip = { version = "0.5.9", optional = true }
shadow-rs = { version = "0.5", default-features = false, optional = true }
[target.'cfg(unix)'.dependencies]
umask = "1.0.0"
users = "0.10.0"
users = "0.11.0"
# TODO this will be possible with new dependency resolver
# (currently on nightly behind -Zfeatures=itarget):
@ -122,8 +122,8 @@ version = "0.24.2"
shadow-rs = "0.5"
[dev-dependencies]
quickcheck = "0.9.2"
quickcheck_macros = "0.9.1"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
[features]
default = ["shadow-rs"]

View File

@ -29,7 +29,7 @@ use rustyline::{self, error::ReadlineError};
use crate::EnvironmentSyncer;
use nu_errors::ShellError;
use nu_parser::ParserScope;
use nu_protocol::{UntaggedValue, Value};
use nu_protocol::{hir::ExternalRedirection, UntaggedValue, Value};
use std::error::Error;
use std::iter::Iterator;
@ -48,16 +48,14 @@ pub fn search_paths() -> Vec<std::path::PathBuf> {
}
if let Ok(config) = nu_data::config::config(Tag::unknown()) {
if let Some(plugin_dirs) = config.get("plugin_dirs") {
if let Value {
value: UntaggedValue::Table(pipelines),
..
} = plugin_dirs
{
for pipeline in pipelines {
if let Ok(plugin_dir) = pipeline.as_string() {
search_paths.push(PathBuf::from(plugin_dir));
}
if let Some(Value {
value: UntaggedValue::Table(pipelines),
..
}) = config.get("plugin_dirs")
{
for pipeline in pipelines {
if let Ok(plugin_dir) = pipeline.as_string() {
search_paths.push(PathBuf::from(plugin_dir));
}
}
}
@ -160,7 +158,9 @@ pub async fn cli(mut context: EvaluationContext) -> Result<(), Box<dyn Error>> {
let prompt_line = prompt.as_string()?;
context.scope.enter_scope();
let (prompt_block, err) = nu_parser::parse(&prompt_line, 0, &context.scope);
let (mut prompt_block, err) = nu_parser::parse(&prompt_line, 0, &context.scope);
prompt_block.set_redirect(ExternalRedirection::Stdout);
if err.is_some() {
context.scope.exit_scope();
@ -412,7 +412,7 @@ mod tests {
#[quickcheck]
fn quickcheck_parse(data: String) -> bool {
let (tokens, err) = nu_parser::lex(&data, 0);
let (lite_block, err2) = nu_parser::block(tokens);
let (lite_block, err2) = nu_parser::parse_block(tokens);
if err.is_none() && err2.is_none() {
let context = basic_evaluation_context().unwrap();
let _ = nu_parser::classify_block(&lite_block, &context.scope);

View File

@ -256,7 +256,7 @@ pub fn completion_location(line: &str, block: &Block, pos: usize) -> Vec<Complet
mod tests {
use super::*;
use nu_parser::{block, classify_block, lex, ParserScope};
use nu_parser::{classify_block, lex, parse_block, ParserScope};
use nu_protocol::{Signature, SyntaxShape};
#[derive(Clone, Debug)]
@ -307,7 +307,7 @@ mod tests {
pos: usize,
) -> Vec<LocationType> {
let (tokens, _) = lex(line, 0);
let (lite_block, _) = block(tokens);
let (lite_block, _) = parse_block(tokens);
scope.enter_scope();
let (block, _) = classify_block(&lite_block, scope);

View File

@ -51,7 +51,7 @@ impl DirectorySpecificEnvironment {
}
}
fn toml_if_trusted(&mut self, nu_env_file: &PathBuf) -> Result<NuEnvDoc, ShellError> {
fn toml_if_trusted(&mut self, nu_env_file: &Path) -> Result<NuEnvDoc, ShellError> {
let content = std::fs::read(&nu_env_file)?;
if autoenv::file_is_trusted(&nu_env_file, &content)? {
@ -161,7 +161,7 @@ impl DirectorySpecificEnvironment {
pub fn maybe_add_key(
&mut self,
seen_vars: &mut IndexSet<EnvKey>,
dir: &PathBuf,
dir: &Path,
key: &str,
val: &str,
) {
@ -169,7 +169,7 @@ impl DirectorySpecificEnvironment {
if !seen_vars.contains(key) {
seen_vars.insert(key.to_string());
self.added_vars
.entry(dir.clone())
.entry(PathBuf::from(dir))
.or_insert(IndexMap::new())
.insert(key.to_string(), var_os(key));

View File

@ -95,9 +95,11 @@ impl EnvironmentSyncer {
ctx.with_host(|host| {
host.env_set(
std::ffi::OsString::from(var.0),
std::ffi::OsString::from(string),
std::ffi::OsString::from(&string),
)
});
ctx.scope.add_env_var_to_base(var.0, string);
}
}
}
@ -128,8 +130,14 @@ impl EnvironmentSyncer {
if let Ok(paths_ready) = prepared {
ctx.with_host(|host| {
host.env_set(std::ffi::OsString::from("PATH"), paths_ready);
host.env_set(
std::ffi::OsString::from("PATH"),
std::ffi::OsString::from(&paths_ready),
);
});
ctx.scope
.add_env_var_to_base("PATH", paths_ready.to_string_lossy().to_string());
}
}
}

View File

@ -58,6 +58,7 @@ pub(crate) use nu_value_ext::ValueExt;
#[allow(unused_imports)]
pub(crate) use std::sync::atomic::Ordering;
#[allow(clippy::clippy::wrong_self_convention)]
pub trait FromInputStream {
fn from_input_stream(self) -> OutputStream;
}
@ -73,6 +74,7 @@ where
}
}
#[allow(clippy::clippy::wrong_self_convention)]
pub trait ToOutputStream {
fn to_output_stream(self) -> OutputStream;
}

View File

@ -119,7 +119,7 @@ impl rustyline::validate::Validator for NuValidator {
}
}
let (_, err) = nu_parser::block(tokens);
let (_, err) = nu_parser::parse_block(tokens);
if let Some(err) = err {
if let nu_errors::ParseErrorReason::Eof { .. } = err.reason() {

View File

@ -211,7 +211,7 @@ fn get_result_shape_of(
l_shape: SyntaxShape,
op_expr: &SpannedExpression,
r_shape: SyntaxShape,
) -> Result<SyntaxShape, ShellError> {
) -> SyntaxShape {
let op = match op_expr.expr {
Expression::Literal(Literal::Operator(op)) => op,
_ => unreachable!("Passing anything but the op expr is invalid"),
@ -220,7 +220,7 @@ fn get_result_shape_of(
//There is some code for that in the evaluator already.
//One might reuse it.
//For now we ignore this issue
Ok(match op {
match op {
Operator::Equal
| Operator::NotEqual
| Operator::LessThan
@ -257,7 +257,8 @@ fn get_result_shape_of(
}
}
Operator::Modulo => SyntaxShape::Number,
})
Operator::Pow => SyntaxShape::Number,
}
}
fn get_shape_of_expr(expr: &SpannedExpression) -> Option<SyntaxShape> {
@ -333,7 +334,7 @@ fn get_result_shape_of_math_expr(
//match lhs, rhs
match (shapes[0], shapes[1]) {
(None, None) | (None, _) | (_, None) => Ok(None),
(Some(left), Some(right)) => get_result_shape_of(left, &bin.op, right).map(Some),
(Some(left), Some(right)) => Ok(Some(get_result_shape_of(left, &bin.op, right))),
}
}
@ -860,7 +861,7 @@ impl VarSyntaxShapeDeductor {
}
}
}
Operator::Multiply | Operator::Divide => {
Operator::Multiply | Operator::Divide | Operator::Pow => {
if let Some(shape) = self.get_shape_of_binary_arg_or_insert_dependency(
(var, expr),
bin_spanned,

View File

@ -5,105 +5,105 @@ description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-command"
version = "0.26.0"
version = "0.27.1"
[lib]
doctest = false
[dependencies]
nu-data = { version = "0.26.0", path = "../nu-data" }
nu-engine = { version = "0.26.0", path = "../nu-engine" }
nu-errors = { version = "0.26.0", path = "../nu-errors" }
nu-json = { version = "0.26.0", path = "../nu-json" }
nu-parser = { version = "0.26.0", path = "../nu-parser" }
nu-plugin = { version = "0.26.0", path = "../nu-plugin" }
nu-protocol = { version = "0.26.0", path = "../nu-protocol" }
nu-source = { version = "0.26.0", path = "../nu-source" }
nu-stream = { version = "0.26.0", path = "../nu-stream" }
nu-table = { version = "0.26.0", path = "../nu-table" }
nu-test-support = { version = "0.26.0", path = "../nu-test-support" }
nu-value-ext = { version = "0.26.0", path = "../nu-value-ext" }
nu-data = { version = "0.27.1", path = "../nu-data" }
nu-engine = { version = "0.27.1", path = "../nu-engine" }
nu-errors = { version = "0.27.1", path = "../nu-errors" }
nu-json = { version = "0.27.1", path = "../nu-json" }
nu-parser = { version = "0.27.1", path = "../nu-parser" }
nu-plugin = { version = "0.27.1", path = "../nu-plugin" }
nu-protocol = { version = "0.27.1", path = "../nu-protocol" }
nu-source = { version = "0.27.1", path = "../nu-source" }
nu-stream = { version = "0.27.1", path = "../nu-stream" }
nu-table = { version = "0.27.1", path = "../nu-table" }
nu-test-support = { version = "0.27.1", path = "../nu-test-support" }
nu-value-ext = { version = "0.27.1", path = "../nu-value-ext" }
Inflector = "0.11"
ansi_term = "0.12.1"
arboard = { version = "1.1.0", optional = true }
async-recursion = "0.3.1"
async-trait = "0.1.40"
async-recursion = "0.3.2"
async-trait = "0.1.42"
base64 = "0.13.0"
bigdecimal = { version = "0.2.0", features = ["serde"] }
byte-unit = "4.0.9"
bytes = "0.5.6"
calamine = "0.16.1"
chrono = { version = "0.4.15", features = ["serde"] }
bytes = "1.0.1"
calamine = "0.17.0"
chrono = { version = "0.4.19", features = ["serde"] }
chrono-tz = "0.5.3"
clap = "2.33.3"
codespan-reporting = "0.11.0"
csv = "1.1.3"
ctrlc = { version = "3.1.6", optional = true }
ctrlc = { version = "3.1.7", optional = true }
derive-new = "0.5.8"
directories-next = { version = "2.0.0", optional = true }
dirs-next = { version = "2.0.0", optional = true }
dtparse = "1.2.0"
dunce = "1.0.1"
eml-parser = "0.1.0"
encoding_rs = "0.8.24"
encoding_rs = "0.8.28"
filesize = "0.2.0"
fs_extra = "1.2.0"
futures = { version = "0.3.5", features = ["compat", "io-compat"] }
futures-util = "0.3.8"
futures = { version = "0.3.12", features = ["compat", "io-compat"] }
futures-util = "0.3.12"
futures_codec = "0.4.1"
getset = "0.1.1"
glob = "0.3.0"
htmlescape = "0.3.1"
ical = "0.7.0"
ichwh = { version = "0.3.4", optional = true }
indexmap = { version = "1.6.0", features = ["serde-1"] }
indexmap = { version = "1.6.1", features = ["serde-1"] }
itertools = "0.10.0"
lazy_static = "1.*"
log = "0.4.11"
log = "0.4.14"
meval = "0.2.0"
num-bigint = { version = "0.3.0", features = ["serde"] }
num-bigint = { version = "0.3.1", features = ["serde"] }
num-format = { version = "0.4.0", features = ["with-num-bigint"] }
num-traits = "0.2.12"
parking_lot = "0.11.0"
num-traits = "0.2.14"
parking_lot = "0.11.1"
pin-utils = "0.1.0"
pretty-hex = "0.2.0"
ptree = { version = "0.3.0", optional = true }
pretty-hex = "0.2.1"
ptree = { version = "0.3.1", optional = true }
query_interface = "0.3.5"
quick-xml = "0.20.0"
quick-xml = "0.21.0"
rand = "0.7.3"
rayon = "1.4.0"
regex = "1.3.9"
rayon = "1.5.0"
regex = "1.4.3"
roxmltree = "0.14.0"
rust-embed = "5.8.0"
rustyline = { version = "6.3.0", optional = true }
serde = { version = "1.0.115", features = ["derive"] }
rust-embed = "5.9.0"
rustyline = { version = "7.1.0", optional = true }
serde = { version = "1.0.123", features = ["derive"] }
serde_bytes = "0.11.5"
serde_ini = "0.2.0"
serde_json = "1.0.57"
serde_json = "1.0.61"
serde_urlencoded = "0.7.0"
serde_yaml = "0.8.13"
sha2 = "0.9.1"
shellexpand = "2.0.0"
serde_yaml = "0.8.16"
sha2 = "0.9.3"
shellexpand = "2.1.0"
strip-ansi-escapes = "0.1.0"
sxd-document = "0.3.2"
sxd-xpath = "0.4.2"
tempfile = "3.1.0"
term = { version = "0.6.1", optional = true }
tempfile = "3.2.0"
term = { version = "0.7.0", optional = true }
term_size = "0.3.2"
termcolor = "1.1.0"
titlecase = "1.0"
toml = "0.5.6"
trash = { version = "1.2.0", optional = true }
unicode-segmentation = "1.6.0"
url = "2.1.1"
uuid_crate = { package = "uuid", version = "0.8.1", features = ["v4"], optional = true }
termcolor = "1.1.2"
titlecase = "1.1.0"
toml = "0.5.8"
trash = { version = "1.3.0", optional = true }
unicode-segmentation = "1.7.1"
url = "2.2.0"
uuid_crate = { package = "uuid", version = "0.8.2", features = ["v4"], optional = true }
which = { version = "4.0.2", optional = true }
zip = { version = "0.5.7", optional = true }
zip = { version = "0.5.9", optional = true }
[target.'cfg(unix)'.dependencies]
umask = "1.0.0"
users = "0.10.0"
users = "0.11.0"
# TODO this will be possible with new dependency resolver
# (currently on nightly behind -Zfeatures=itarget):
@ -120,8 +120,8 @@ version = "0.24.2"
shadow-rs = "0.5"
[dev-dependencies]
quickcheck = "0.9.2"
quickcheck_macros = "0.9.1"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
[features]
clipboard-cli = ["arboard"]

View File

@ -115,6 +115,7 @@ pub(crate) mod split_by;
pub(crate) mod str_;
pub(crate) mod table;
pub(crate) mod tags;
pub(crate) mod termsize;
pub(crate) mod to;
pub(crate) mod to_csv;
pub(crate) mod to_html;
@ -197,7 +198,7 @@ pub(crate) use from_xlsx::FromXLSX;
pub(crate) use from_xml::FromXML;
pub(crate) use from_yaml::FromYAML;
pub(crate) use from_yaml::FromYML;
pub(crate) use get::Get;
pub(crate) use get::Command as Get;
pub(crate) use group_by::Command as GroupBy;
pub(crate) use group_by_date::GroupByDate;
pub(crate) use hash_::{Hash, HashBase64};
@ -245,7 +246,7 @@ pub(crate) use reverse::Reverse;
pub(crate) use rm::Remove;
pub(crate) use run_external::RunExternalCommand;
pub(crate) use save::Save;
pub(crate) use select::Select;
pub(crate) use select::Command as Select;
pub(crate) use seq::Seq;
pub(crate) use seq_dates::SeqDates;
pub(crate) use shells::Shells;
@ -265,11 +266,12 @@ pub(crate) use str_::{
};
pub(crate) use table::Table;
pub(crate) use tags::Tags;
pub(crate) use termsize::TermSize;
pub(crate) use to::To;
pub(crate) use to_csv::ToCSV;
pub(crate) use to_html::ToHTML;
pub(crate) use to_json::ToJSON;
pub(crate) use to_md::ToMarkdown;
pub(crate) use to_md::Command as ToMarkdown;
pub(crate) use to_toml::ToTOML;
pub(crate) use to_tsv::ToTSV;
pub(crate) use to_url::ToURL;
@ -299,6 +301,8 @@ mod tests {
whole_stream_command(Move),
whole_stream_command(Update),
whole_stream_command(Empty),
// whole_stream_command(Select),
// whole_stream_command(Get),
// Str Command Suite
whole_stream_command(Str),
whole_stream_command(StrToDecimal),
@ -327,6 +331,7 @@ mod tests {
whole_stream_command(StrKebabCase),
whole_stream_command(StrSnakeCase),
whole_stream_command(StrScreamingSnakeCase),
whole_stream_command(ToMarkdown),
]
}

View File

@ -286,6 +286,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Ansi {})?)
test_examples(Ansi {})
}
}

View File

@ -6,7 +6,7 @@ use serde::Deserialize;
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::io::Read;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
pub struct Autoenv;
#[derive(Deserialize, Serialize, Debug, Default)]
@ -20,11 +20,12 @@ impl Trusted {
}
}
}
pub fn file_is_trusted(nu_env_file: &PathBuf, content: &[u8]) -> Result<bool, ShellError> {
pub fn file_is_trusted(nu_env_file: &Path, content: &[u8]) -> Result<bool, ShellError> {
let contentdigest = Sha256::digest(&content).as_slice().to_vec();
let nufile = std::fs::canonicalize(nu_env_file)?;
let trusted = read_trusted()?;
Ok(trusted.files.get(&nufile.to_string_lossy().to_string()) == Some(&contentdigest))
}

View File

@ -173,6 +173,13 @@ pub async fn autoview(context: RunnableContext) -> Result<OutputStream, ShellErr
let output = format_leaf(&x).plain_string(100_000);
out!("{}", output);
}
Value {
value: UntaggedValue::Primitive(Primitive::Filesize(_)),
..
} => {
let output = format_leaf(&x).plain_string(100_000);
out!("{}", output);
}
Value {
value: UntaggedValue::Primitive(Primitive::Date(d)),
..
@ -309,6 +316,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Command {})?)
test_examples(Command {})
}
}

View File

@ -70,7 +70,7 @@ impl WholeStreamCommand for Benchmark {
async fn benchmark(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let tag = raw_args.call_info.args.span;
let mut context = EvaluationContext::from_raw(&raw_args);
let mut context = EvaluationContext::from_args(&raw_args);
let scope = raw_args.scope.clone();
let (BenchmarkArgs { block, passthrough }, input) = raw_args.process().await?;

View File

@ -337,6 +337,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Cal {})?)
test_examples(Cal {})
}
}

View File

@ -67,6 +67,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Cd {})?)
test_examples(Cd {})
}
}

View File

@ -143,6 +143,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Char {})?)
test_examples(Char {})
}
}

View File

@ -42,6 +42,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Chart {})?)
test_examples(Chart {})
}
}

View File

@ -101,6 +101,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Clip {})?)
test_examples(Clip {})
}
}

View File

@ -81,6 +81,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Compact {})?)
test_examples(Compact {})
}
}

View File

@ -81,6 +81,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Count {})?)
test_examples(Count {})
}
}

View File

@ -58,6 +58,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Cpy {})?)
test_examples(Cpy {})
}
}

View File

@ -35,6 +35,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Command {})?)
test_examples(Command {})
}
}

View File

@ -104,6 +104,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Date {})?)
test_examples(Date {})
}
}

View File

@ -70,6 +70,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Date {})?)
test_examples(Date {})
}
}

View File

@ -45,6 +45,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Date {})?)
test_examples(Date {})
}
}

View File

@ -100,6 +100,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Date {})?)
test_examples(Date {})
}
}

View File

@ -105,6 +105,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Date {})?)
test_examples(Date {})
}
}

View File

@ -50,6 +50,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Date {})?)
test_examples(Date {})
}
}

View File

@ -53,6 +53,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Debug {})?)
test_examples(Debug {})
}
}

View File

@ -80,6 +80,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Default {})?)
test_examples(Default {})
}
}

View File

@ -237,6 +237,7 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
whole_stream_command(UrlQuery),
whole_stream_command(Seq),
whole_stream_command(SeqDates),
whole_stream_command(TermSize),
]);
#[cfg(feature = "clipboard-cli")]

View File

@ -49,6 +49,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Describe {})?)
test_examples(Describe {})
}
}

View File

@ -55,7 +55,7 @@ impl WholeStreamCommand for Do {
async fn do_(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let external_redirection = raw_args.call_info.args.external_redirection;
let context = EvaluationContext::from_raw(&raw_args);
let context = EvaluationContext::from_args(&raw_args);
let (
DoArgs {
ignore_errors,
@ -113,6 +113,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Do {})?)
test_examples(Do {})
}
}

View File

@ -86,6 +86,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Drop {})?)
test_examples(Drop {})
}
}

View File

@ -168,6 +168,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Du {})?)
test_examples(Du {})
}
}

View File

@ -111,7 +111,7 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value {
}
async fn each(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let context = Arc::new(EvaluationContext::from_raw(&raw_args));
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (each_args, input): (EachArgs, _) = raw_args.process().await?;
let block = Arc::new(Box::new(each_args.block));
@ -160,6 +160,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Each {})?)
test_examples(Each {})
}
}

View File

@ -46,7 +46,7 @@ impl WholeStreamCommand for EachGroup {
}
async fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let context = Arc::new(EvaluationContext::from_raw(&raw_args));
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (each_args, input): (EachGroupArgs, _) = raw_args.process().await?;
let block = Arc::new(Box::new(each_args.block));
@ -111,6 +111,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(EachGroup {})?)
test_examples(EachGroup {})
}
}

View File

@ -51,7 +51,7 @@ impl WholeStreamCommand for EachWindow {
}
async fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let context = Arc::new(EvaluationContext::from_raw(&raw_args));
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (each_args, mut input): (EachWindowArgs, _) = raw_args.process().await?;
let block = Arc::new(Box::new(each_args.block));
@ -100,6 +100,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(EachWindow {})?)
test_examples(EachWindow {})
}
}

View File

@ -200,6 +200,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Echo {})?)
test_examples(Echo {})
}
}

View File

@ -6,10 +6,10 @@ use nu_protocol::{
hir::CapturedBlock, ColumnPath, Primitive, ReturnSuccess, Signature, SyntaxShape,
UntaggedValue, Value,
};
use nu_source::Tagged;
use nu_value_ext::{as_string, ValueExt};
use crate::utils::arguments::arguments;
use futures::stream::once;
use nu_value_ext::{as_string, ValueExt};
#[derive(Deserialize)]
pub struct Arguments {
@ -84,9 +84,10 @@ impl WholeStreamCommand for Command {
async fn is_empty(args: CommandArgs) -> Result<OutputStream, ShellError> {
let tag = args.call_info.name_tag.clone();
let name_tag = Arc::new(args.call_info.name_tag.clone());
let context = Arc::new(EvaluationContext::from_raw(&args));
let (Arguments { rest }, input) = args.process().await?;
let (columns, default_block): (Vec<ColumnPath>, Option<Box<CapturedBlock>>) = arguments(rest)?;
let context = Arc::new(EvaluationContext::from_args(&args));
let (Arguments { mut rest }, input) = args.process().await?;
let (columns, default_block): (Vec<ColumnPath>, Option<Box<CapturedBlock>>) =
arguments(&mut rest)?;
let default_block = Arc::new(default_block);
if input.is_empty() {
@ -130,37 +131,6 @@ async fn is_empty(args: CommandArgs) -> Result<OutputStream, ShellError> {
.to_output_stream())
}
fn arguments(
rest: Vec<Value>,
) -> Result<(Vec<ColumnPath>, Option<Box<CapturedBlock>>), ShellError> {
let mut rest = rest;
let mut columns = vec![];
let mut default = None;
let last_argument = rest.pop();
match last_argument {
Some(Value {
value: UntaggedValue::Block(call),
..
}) => default = Some(call),
Some(other) => {
let Tagged { item: path, .. } = other.as_column_path()?;
columns = vec![path];
}
None => {}
};
for argument in rest {
let Tagged { item: path, .. } = argument.as_column_path()?;
columns.push(path);
}
Ok((columns, default))
}
async fn process_row(
context: Arc<EvaluationContext>,
input: Value,

View File

@ -189,6 +189,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Enter {})?)
test_examples(Enter {})
}
}

View File

@ -93,6 +93,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Every {})?)
test_examples(Every {})
}
}

View File

@ -59,6 +59,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Exit {})?)
test_examples(Exit {})
}
}

View File

@ -72,6 +72,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(First {})?)
test_examples(First {})
}
}

View File

@ -57,9 +57,7 @@ async fn flatten(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (Arguments { rest: columns }, input) = args.process().await?;
Ok(input
.map(move |item| {
futures::stream::iter(flat_value(&columns, &item, &tag).into_iter().flatten())
})
.map(move |item| futures::stream::iter(flat_value(&columns, &item, &tag).into_iter()))
.flatten()
.to_output_stream())
}
@ -72,7 +70,7 @@ fn flat_value(
columns: &[Tagged<String>],
item: &Value,
name_tag: impl Into<Tag>,
) -> Result<Vec<Result<ReturnSuccess, ShellError>>, ShellError> {
) -> Vec<Result<ReturnSuccess, ShellError>> {
let tag = item.tag.clone();
let name_tag = name_tag.into();
@ -121,7 +119,7 @@ fn flat_value(
name_tag.span
};
return Ok(vec![ReturnSuccess::value(
return vec![ReturnSuccess::value(
UntaggedValue::Error(ShellError::labeled_error_with_secondary(
"can only flatten one inner table at the same time",
"tried flattening more than one column with inner tables",
@ -130,7 +128,7 @@ fn flat_value(
already_flattened,
))
.into_value(name_tag),
)]);
)];
}
if !columns.is_empty() {
@ -179,5 +177,5 @@ fn flat_value(
}
};
Ok(res.into_iter().map(ReturnSuccess::value).collect())
res.into_iter().map(ReturnSuccess::value).collect()
}

View File

@ -145,6 +145,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Format {})?)
test_examples(Format {})
}
}

View File

@ -1,16 +1,13 @@
use crate::prelude::*;
use nu_errors::ShellError;
use nu_data::base::shape::InlineShape;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{
ColumnPath, Primitive::Filesize, ReturnSuccess, Signature, SyntaxShape, UntaggedValue,
UntaggedValue::Primitive, Value,
ColumnPath, Primitive::Filesize, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value,
};
use nu_source::Tagged;
use nu_value_ext::get_data_by_column_path;
use num_format::{Locale, ToFormattedString};
pub struct FileSize;
#[derive(Deserialize)]
@ -71,12 +68,25 @@ async fn process_row(
Ok({
let replace_for = get_data_by_column_path(&input, &field, move |_, _, error| error);
match replace_for {
Ok(s) => match convert_bytes_to_string_using_format(s, format) {
Ok(b) => OutputStream::one(ReturnSuccess::value(
input.replace_data_at_column_path(&field, b).expect("Given that the existence check was already done, this shouldn't trigger never"),
)),
Err(e) => OutputStream::one(Err(e)),
},
Ok(s) => {
if let Value {
value: UntaggedValue::Primitive(Filesize(fs)),
..
} = s
{
let byte_format = InlineShape::format_bytes(&fs, Some(&format.item));
let byte_value = Value::from(byte_format.1);
OutputStream::one(ReturnSuccess::value(
input.replace_data_at_column_path(&field, byte_value).expect("Given that the existence check was already done, this shouldn't trigger never"),
))
} else {
return Err(ShellError::labeled_error(
"the data in this row is not of the type filesize",
"invalid datatype in row",
input.tag(),
));
}
}
Err(e) => OutputStream::one(Err(e)),
}
})
@ -102,76 +112,6 @@ async fn filesize(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
.to_output_stream())
}
fn convert_bytes_to_string_using_format(
bytes: Value,
format: Tagged<String>,
) -> Result<Value, ShellError> {
match bytes.value {
Primitive(Filesize(b)) => {
let byte = byte_unit::Byte::from_bytes(b as u128);
let value = match format.item().to_lowercase().as_str() {
"b" => Ok(UntaggedValue::string(b.to_formatted_string(&Locale::en))),
"kb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::KB).to_string(),
)),
"kib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::KiB).to_string(),
)),
"mb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::MB).to_string(),
)),
"mib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::MiB).to_string(),
)),
"gb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::GB).to_string(),
)),
"gib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::GiB).to_string(),
)),
"tb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::TB).to_string(),
)),
"tib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::TiB).to_string(),
)),
"pb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::PB).to_string(),
)),
"pib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::PiB).to_string(),
)),
"eb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::EB).to_string(),
)),
"eib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::EiB).to_string(),
)),
"zb" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::ZB).to_string(),
)),
"zib" => Ok(UntaggedValue::string(
byte.get_adjusted_unit(byte_unit::ByteUnit::ZiB).to_string(),
)),
_ => Err(ShellError::labeled_error(
format!("Invalid format code: {:}", format.item()),
"invalid format",
format.tag(),
)),
};
match value {
Ok(b) => Ok(Value { value: b, ..bytes }),
Err(e) => Err(e),
}
}
_ => Err(ShellError::labeled_error(
"the data in this row is not of the type filesize",
"invalid row type",
bytes.tag(),
)),
}
}
#[cfg(test)]
mod tests {
use super::FileSize;
@ -181,6 +121,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FileSize {})?)
test_examples(FileSize {})
}
}

View File

@ -35,6 +35,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(From {})?)
test_examples(From {})
}
}

View File

@ -107,6 +107,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromCSV {})?)
test_examples(FromCSV {})
}
}

View File

@ -128,6 +128,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromEML {})?)
test_examples(FromEML {})
}
}

View File

@ -247,6 +247,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromIcs {})?)
test_examples(FromIcs {})
}
}

View File

@ -93,6 +93,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromINI {})?)
test_examples(FromINI {})
}
}

View File

@ -142,6 +142,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromJSON {})?)
test_examples(FromJSON {})
}
}

View File

@ -100,6 +100,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromODS {})?)
test_examples(FromODS {})
}
}

View File

@ -227,7 +227,7 @@ fn from_ssv_string_to_value(
aligned_columns: bool,
split_at: usize,
tag: impl Into<Tag>,
) -> Option<Value> {
) -> Value {
let tag = tag.into();
let rows = string_to_table(s, headerless, aligned_columns, split_at)
.iter()
@ -244,7 +244,7 @@ fn from_ssv_string_to_value(
})
.collect();
Some(UntaggedValue::Table(rows).into_value(&tag))
UntaggedValue::Table(rows).into_value(&tag)
}
async fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
@ -271,23 +271,13 @@ async fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
split_at,
name.clone(),
) {
Some(x) => match x {
Value {
value: UntaggedValue::Table(list),
..
} => futures::stream::iter(list.into_iter().map(ReturnSuccess::value))
.to_output_stream(),
x => OutputStream::one(ReturnSuccess::value(x)),
},
None => {
return Err(ShellError::labeled_error_with_secondary(
"Could not parse as SSV",
"input cannot be parsed ssv",
&name,
"value originates from here",
&concat_string.tag,
));
Value {
value: UntaggedValue::Table(list),
..
} => {
futures::stream::iter(list.into_iter().map(ReturnSuccess::value)).to_output_stream()
}
x => OutputStream::one(ReturnSuccess::value(x)),
},
)
}
@ -502,6 +492,6 @@ mod tests {
use super::FromSSV;
use crate::examples::test as test_examples;
Ok(test_examples(FromSSV {})?)
test_examples(FromSSV {})
}
}

View File

@ -99,6 +99,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromTOML {})?)
test_examples(FromTOML {})
}
}

View File

@ -50,6 +50,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromTSV {})?)
test_examples(FromTSV {})
}
}

View File

@ -62,6 +62,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromURL {})?)
test_examples(FromURL {})
}
}

View File

@ -102,6 +102,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromVcf {})?)
test_examples(FromVcf {})
}
}

View File

@ -100,6 +100,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromXLSX {})?)
test_examples(FromXLSX {})
}
}

View File

@ -301,6 +301,6 @@ mod tests {
use super::FromXML;
use crate::examples::test as test_examples;
Ok(test_examples(FromXML {})?)
test_examples(FromXML {})
}
}

View File

@ -130,7 +130,7 @@ pub fn from_yaml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value
&tag,
)
})?;
Ok(convert_yaml_value_to_nu_value(&v, tag)?)
convert_yaml_value_to_nu_value(&v, tag)
}
async fn from_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
@ -169,7 +169,7 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(FromYAML {})?)
test_examples(FromYAML {})
}
#[test]

View File

@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::utils::arguments::arguments;
use indexmap::set::IndexSet;
use log::trace;
use nu_engine::WholeStreamCommand;
@ -10,22 +11,22 @@ use nu_protocol::{
use nu_source::HasFallibleSpan;
use nu_value_ext::get_data_by_column_path;
pub struct Get;
pub struct Command;
#[derive(Deserialize)]
pub struct GetArgs {
rest: Vec<ColumnPath>,
pub struct Arguments {
rest: Vec<Value>,
}
#[async_trait]
impl WholeStreamCommand for Get {
impl WholeStreamCommand for Command {
fn name(&self) -> &str {
"get"
}
fn signature(&self) -> Signature {
Signature::build("get").rest(
SyntaxShape::ColumnPath,
SyntaxShape::Any,
"optionally return additional data by path",
)
}
@ -55,7 +56,9 @@ impl WholeStreamCommand for Get {
}
pub async fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
let (GetArgs { rest: column_paths }, mut input) = args.process().await?;
let (Arguments { mut rest }, mut input) = args.process().await?;
let (column_paths, _) = arguments(&mut rest)?;
if column_paths.is_empty() {
let vec = input.drain_vec().await;
@ -255,16 +258,3 @@ pub fn get_column_from_row_error(
)),
}
}
#[cfg(test)]
mod tests {
use super::Get;
use super::ShellError;
#[test]
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Get {})?)
}
}

View File

@ -46,13 +46,13 @@ impl WholeStreamCommand for Command {
result: Some(vec![UntaggedValue::row(indexmap! {
"File".to_string() => UntaggedValue::Table(vec![
UntaggedValue::row(indexmap! {
"name".to_string() => UntaggedValue::string("Andrés.txt").into(),
"name".to_string() => UntaggedValue::string("Andres.txt").into(),
"type".to_string() => UntaggedValue::string("File").into(),
"chickens".to_string() => UntaggedValue::int(10).into(),
"modified".to_string() => date("2019-07-23".tagged_unknown()).unwrap().into(),
}).into(),
UntaggedValue::row(indexmap! {
"name".to_string() => UntaggedValue::string("Andrés.txt").into(),
"name".to_string() => UntaggedValue::string("Darren.txt").into(),
"type".to_string() => UntaggedValue::string("File").into(),
"chickens".to_string() => UntaggedValue::int(20).into(),
"modified".to_string() => date("2019-09-24".tagged_unknown()).unwrap().into(),
@ -130,7 +130,7 @@ enum Grouper {
pub async fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
let name = args.call_info.name_tag.clone();
let context = Arc::new(EvaluationContext::from_raw(&args));
let context = Arc::new(EvaluationContext::from_args(&args));
let (Arguments { grouper }, input) = args.process().await?;
let values: Vec<Value> = input.collect().await;

View File

@ -139,6 +139,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(GroupByDate {})?)
test_examples(GroupByDate {})
}
}

View File

@ -38,6 +38,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Command {})?)
test_examples(Command {})
}
}

View File

@ -114,6 +114,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Headers {})?)
test_examples(Headers {})
}
}

View File

@ -217,6 +217,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Help {})?)
test_examples(Help {})
}
}

View File

@ -225,6 +225,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Histogram {})?)
test_examples(Histogram {})
}
}

View File

@ -77,6 +77,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(History {})?)
test_examples(History {})
}
}

View File

@ -66,7 +66,7 @@ impl WholeStreamCommand for If {
}
async fn if_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let tag = raw_args.call_info.name_tag.clone();
let context = Arc::new(EvaluationContext::from_raw(&raw_args));
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (
IfArgs {
@ -137,6 +137,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(If {})?)
test_examples(If {})
}
}

View File

@ -154,7 +154,7 @@ async fn process_row(
}
async fn insert(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let context = Arc::new(EvaluationContext::from_raw(&raw_args));
let context = Arc::new(EvaluationContext::from_args(&raw_args));
let (Arguments { column, value }, input) = raw_args.process().await?;
let value = Arc::new(value);
let column = Arc::new(column);

View File

@ -31,11 +31,18 @@ impl WholeStreamCommand for IntoInt {
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Convert filesize to integer",
example: "into-int 1kb | each { = $it / 1024 }",
result: Some(vec![UntaggedValue::int(1).into()]),
}]
vec![
Example {
description: "Convert filesize to integer",
example: "into-int 1kb | each { = $it / 1000 }",
result: Some(vec![UntaggedValue::int(1).into()]),
},
Example {
description: "Convert filesize to integer",
example: "into-int 1kib | each { = $it / 1024 }",
result: Some(vec![UntaggedValue::int(1).into()]),
},
]
}
}
@ -76,6 +83,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(IntoInt {})?)
test_examples(IntoInt {})
}
}

View File

@ -74,6 +74,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Command {})?)
test_examples(Command {})
}
}

View File

@ -109,6 +109,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -108,6 +108,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -120,6 +120,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Kill {})?)
test_examples(Kill {})
}
}

View File

@ -83,6 +83,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Last {})?)
test_examples(Last {})
}
}

View File

@ -124,6 +124,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Lines {})?)
test_examples(Lines {})
}
}

View File

@ -78,6 +78,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Ls {})?)
test_examples(Ls {})
}
}

View File

@ -64,6 +64,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -59,12 +59,9 @@ impl WholeStreamCommand for SubCommand {
fn to_byte(value: &Value) -> Option<Value> {
match &value.value {
UntaggedValue::Primitive(Primitive::Int(num)) => Some(
UntaggedValue::Primitive(Primitive::Filesize(convert_number_to_u64(&Number::Int(
num.clone(),
))))
.into_untagged_value(),
),
UntaggedValue::Primitive(Primitive::Int(num)) => {
Some(UntaggedValue::Primitive(Primitive::Filesize(num.clone())).into_untagged_value())
}
_ => None,
}
}
@ -95,7 +92,7 @@ pub fn average(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
Value {
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
..
} => UntaggedValue::int(*num as usize).into_untagged_value(),
} => UntaggedValue::int(num.clone()).into_untagged_value(),
other => other.clone(),
})
.collect::<Vec<_>>(),
@ -116,7 +113,7 @@ pub fn average(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
..
} => {
let left = UntaggedValue::from(Primitive::Int(num.into()));
let left = UntaggedValue::from(Primitive::Int(num));
let result = nu_data::value::compute_values(Operator::Divide, &left, &total_rows);
match result {
@ -190,6 +187,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -81,6 +81,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -41,7 +41,7 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Command {})?)
test_examples(Command {})
}
#[test]

View File

@ -113,6 +113,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -81,6 +81,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -60,6 +60,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -137,7 +137,7 @@ fn compute_average(values: &[Value], name: impl Into<Tag>) -> Result<Value, Shel
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
..
} => {
let left = UntaggedValue::from(Primitive::Int(num.into()));
let left = UntaggedValue::from(Primitive::Int(num));
let result = nu_data::value::compute_values(Operator::Divide, &left, &total_rows);
match result {
@ -189,6 +189,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -60,6 +60,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -85,6 +85,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -3,10 +3,7 @@ use crate::commands::math::utils::run_with_function;
use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{
hir::{convert_number_to_u64, Number},
Primitive, Signature, UntaggedValue, Value,
};
use nu_protocol::{Primitive, Signature, UntaggedValue, Value};
pub struct SubCommand;
@ -51,12 +48,9 @@ impl WholeStreamCommand for SubCommand {
fn to_byte(value: &Value) -> Option<Value> {
match &value.value {
UntaggedValue::Primitive(Primitive::Int(num)) => Some(
UntaggedValue::Primitive(Primitive::Filesize(convert_number_to_u64(&Number::Int(
num.clone(),
))))
.into_untagged_value(),
),
UntaggedValue::Primitive(Primitive::Int(num)) => {
Some(UntaggedValue::Primitive(Primitive::Filesize(num.clone())).into_untagged_value())
}
_ => None,
}
}
@ -78,7 +72,7 @@ pub fn product(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
Value {
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
..
} => UntaggedValue::int(*num as usize).into_untagged_value(),
} => UntaggedValue::int(num.clone()).into_untagged_value(),
other => other.clone(),
})
.collect::<Vec<_>>(),
@ -117,6 +111,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -99,6 +99,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -144,6 +144,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -4,10 +4,7 @@ use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{
hir::{convert_number_to_u64, Number},
Primitive, Signature, UntaggedValue, Value,
};
use nu_protocol::{Primitive, Signature, UntaggedValue, Value};
pub struct SubCommand;
@ -59,12 +56,9 @@ impl WholeStreamCommand for SubCommand {
fn to_byte(value: &Value) -> Option<Value> {
match &value.value {
UntaggedValue::Primitive(Primitive::Int(num)) => Some(
UntaggedValue::Primitive(Primitive::Filesize(convert_number_to_u64(&Number::Int(
num.clone(),
))))
.into_untagged_value(),
),
UntaggedValue::Primitive(Primitive::Int(num)) => {
Some(UntaggedValue::Primitive(Primitive::Filesize(num.clone())).into_untagged_value())
}
_ => None,
}
}
@ -90,7 +84,7 @@ pub fn summation(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
Value {
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
..
} => UntaggedValue::int(*num as usize).into_untagged_value(),
} => UntaggedValue::int(num.clone()).into_untagged_value(),
other => other.clone(),
})
.collect::<Vec<_>>(),
@ -131,6 +125,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -130,7 +130,7 @@ fn sum_of_squares(values: &[Value], name: &Tag) -> Result<Value, ShellError> {
value: UntaggedValue::Primitive(Primitive::Filesize(num)),
..
} => {
UntaggedValue::from(Primitive::Int(num.clone().into()))
UntaggedValue::from(Primitive::Int(num.clone()))
},
Value {
value: UntaggedValue::Primitive(num),
@ -243,6 +243,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(SubCommand {})?)
test_examples(SubCommand {})
}
}

View File

@ -47,7 +47,7 @@ impl WholeStreamCommand for Merge {
}
async fn merge(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
let context = EvaluationContext::from_raw(&raw_args);
let context = EvaluationContext::from_args(&raw_args);
let name_tag = raw_args.call_info.name_tag.clone();
let (merge_args, input): (MergeArgs, _) = raw_args.process().await?;
let block = merge_args.block;
@ -103,6 +103,6 @@ mod tests {
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
Ok(test_examples(Merge {})?)
test_examples(Merge {})
}
}

Some files were not shown because too many files have changed in this diff Show More