* Make json require string and pass around metadata
The json deserializer was accepting any inputs by coercing non-strings
into strings. As an example, if the input was `[1, 2]` the coercion
would turn into `[12]` and deserialize as a list containing number
twelve instead of a list of two numbers, one and two. This could lead
to silent data corruption.
Aside from that pipeline metadata wasn't passed aroud.
This commit fixes the type issue by adding a strict conversion
function that errors if the input type is not a string or external
stream. It then uses this function instead of the original
`collect_string()`. In addition, this function returns the pipeline
metadata so it can be passed along.
* Make other formats require string
The problem with json coercing non-string types to string was present in
all other text formats. This reuses the `collect_string_strict` function
to fix them.
* `IntoPipelineData` cleanup
The method `into_pipeline_data_with_metadata` can now be conveniently
used.
* add signature information when help on one command
* tell user that one command support operated on cell paths
Also, make type output to be more friendly, like `record<>` should just be `record`
And the same to `table<>`, which should be `table`
* simplify code
* don't show signatures for parser keyword
* update comment
* output arg syntax shape as type, so it's the same as describe command
* fix string when no positional args
* update signature body
* update
* add help signature test
* fix arg output format for composed data type like list or record
* fix clippy
* add comment
* Grouped config commands better
* Tweaked test slightly
* Fix merge conflict(?)
* Remove recently-added test case
* Revert rm.always_trash default
* Untweak rm help messages
* Formatting
* Remove example
* Add deprecation warning
* Remove deprecation timeline
Not sure we want to commit to a specific timeline just yet
Co-authored-by: Reilly Wood <26268125+rgwood@users.noreply.github.com>
* removes unused features.
* Adds back multithreading feature to sysinfo.
* Adds back alloc for percent-encoding
* Adds updated lock file.
* Missed one sysinfo.
* `indexmap` just defaults
* Revert `miette``default-features=false`
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This adds support for (limited) mutable variables. Mutable variables are created with mut much the same way immutable variables are made with let.
Mutable variables allow mutation via the assignment operator (=).
❯ mut x = 100
❯ $x = 200
❯ print $x
200
Mutable variables are limited in that they're only tended to be used in the local code block. Trying to capture a local variable will result in an error:
❯ mut x = 123; {|| $x }
Error: nu::parser::expected_keyword (link)
× Capture of mutable variable.
The intent of this limitation is to reduce some of the issues with mutable variables in general: namely they make code that's harder to reason about. By reducing the scope that a mutable variable can be used it, we can help create local reasoning about them.
Mutation can occur with fields as well, as in this case:
❯ mut y = {abc: 123}
❯ $y.abc = 456
❯ $y
On a historical note: mutable variables are something that we resisted for quite a long time, leaning as much as we could on the functional style of pipelines and dataflow. That said, we've watched folks struggle to work with reduce as an approximation for patterns that would be trivial to express with local mutation. With that in mind, we're leaning towards the happy path.
- Custom commands are true for builtin and custom
- Add classification as external command
- Specify wildcard in keyword: keyword is true for builtin and keyword
* Fix ignore-errors for select
* fix Value::List match
* fix invalid rows
* add tests
* fix ListStream match
* add one more test for ListStream
* add more tests
* tweak words
* Add failing test that list of ints and floats is List<Number>
* Start defining subtype relation
* Make it possible to declare input and output types for commands
- Enforce them in tests
* Declare input and output types of commands
* Add formatted signatures to `help commands` table
* Revert SyntaxShape::Table -> Type::Table change
* Revert unnecessary derive(Hash) on SyntaxShape
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Allows use of slightly optimized variants that check if they have to use
the heavier vte parser. Tries to avoid unnnecessary allocations. Initial
performance characteristics proven out in #4378.
Also reduces boilerplate with right-ward drift.
* fix: fixcd
try to fix
Log: try to fix the bug with can enter a permisson error fold
* change wording
* fat
* fmt
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
* make format filesize more flexible
* make code simpler
* finish refactor on bytes commands
* finish refactor on str commands
* fimplify code
* rename from column_paths to cell_paths
* fix: ✨ "saner" default for mv
fixes#6747
As highlighted in the issue, the default behavior of nu currently
is to overwrite the destination file without notice.
This is not a "standard" expectation users that want this behavior
can create a dedicated alias.
* fix: 📝 edit the comment
* fix: ✨ updated the tests
* fix: 🚧 use --force for case test
This reduces the number of dependencies to build for `cargo build` or
`cargo run` by around 19.
Will not speed up CI as we need to `cargo test` but should help for
`cargo install` or users just building from source.
Time saved on my machine ~0.8 secs so likely unnoticable in noise.
Larger future goal is reducing longer dependency chains to allow more
parallel compilation.
Fixes#6895
Warning: `Iterator::map_while` does not return a `FusedIterator`!
Depending on the consuming adaptor or code (e.g. for loop) the iteration
may be stopped but this is not guaranteed.
Adds a test example but Examples handle iterators like
`FusedIterator` and thus don't catch the regression
Cleanup the message on another test
Disable backtrace on miette
- gimli crate requires several seconds
Disable diagnostics on wax
- depends on an outdated miette version
Builds fine, no observable loss in diagnostics quality of life
Removes 10 crates that have to be compiled.
* Remove unnecessary `#[allow]` annots
Reduce the number of lint exceptions that are not necessary with the
current state of the code (or more recent toolchain)
* Remove dead code from `FileStructure` in nu-command
* Replace `allow(unused)` with relevant feature switch
* Deal with `needless_collect` with annotations
* Change hack for needless_collect in `from json`
This change obviates the need for `allow(needless_collect)`
Removes a pessimistic allocation for empty strings, but increases
allocation size to `Value`
Probably not really worth it.
* Revert "Deal with `needless_collect` with annotations"
This reverts commit 05aca98445.
The previous state seems to better from a performance perspective as a
`Vec<String>` is lighter weight than `Vec<Value>`
* Wrap `open` parse errors from `from` commands
Minimal fix for #6843
This propagates the underlying errors from the called `from` commands
and adds a top-level error with the full path and the understood file
extension and resulting called command.
* Repoint inner span for `from ...` to `open`
* Add actionable message: refer to help or use --raw
* Add support to render right prompt on last line of the prompt
* reset reedline to main branch
* update reedline to fix right prompt to be rendered correctly
* reset reedline to main branch again
* Make Tab insert (partial) completion instead of select next menu item
* Use reedline feature branch
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
* Filter out empty glob patterns
An empty argument to the "glob" command will now produce an empty result.
Working towards nushell/nushell#6653.
* Run `cargo fmt --all`
Just autoformatted the repo so that CI passes and we have a consistent code
format across modules.
* Treat empty glob argument as error
The glob command will now report an empty string argument as an error instead
of silently ignoring it.
See https://github.com/nushell/nushell/pull/6707#discussion_r993345013.
* Add tests for glob command
Two small tests for the glob command, one to check that the empty string errors
it, and another to sanity check the '*' glob, have been added.
* Rename glob sanity check star test
Co-authored-by: Kyle Anderson <kyle.anderson@uwaterloo.ca>
* Add search terms for uppercase
* Add search terms
* Add search terms
* Change to parse
* Add search terms for from
* Add search terms for to
* Remove duplicate function
* Remove duplication of search terms
* Remove search term
* add a new command to query the registry on windows
* cross platform tweaks
* return nushell datatype
* change visibility of exec and registry commands
* Revert "Revert "Try again: in unix like system, set foreground process while running external command (#6273)" (#6542)"
This reverts commit 2bb367f570.
* Make foreground job control hopefully work correctly
These changes are mostly inspired by the glibc manual.
* Fix typo in external command description
* Only restore tty control to shell when no fg procs are left; reuse pgrp
* Rework terminal acquirement code to be like fish
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
* remove export_env command
* remove several export env usage in test code
* adjust hiding relative test case
* fix clippy
* adjust tests
* update tests
* unignore these tests to expose ut failed
* using `use` instead of `overlay use` in some tests
* Revert "using `use` instead of `overlay use` in some tests"
This reverts commit 2ae24b24c3.
* Revert "adjust hiding relative test case"
This reverts commit 4369af6d05.
* Bring back module example
* Revert "update tests"
This reverts commit 6ae94ef513.
* Fix tests
* "Fix" a test
* Remove remaining deprecated env functionality
* Re-enable environment hiding for `hide`
To not break virtualenv since the overlay update is not merged yet
* Fix hiding env in `hide` and ignore some tests
Co-authored-by: kubouch <kubouch@gmail.com>
* fix issue 6602 (broken highlighting in find)
Find uses highlight_search_string to see where the string was found. The problem was that the style would just "append" to the existing haystack (including the ANSI escape codes of LS_COLORS).
This first strips the ANSI escape codes out of the haystack before formatting the
output string.
* update formatting
* Copy lev_distance.rs from the rust compiler
* Minor changes to code from rust compiler
* "Did you mean" suggestions: test instrumented to generate markdown report
* Did you mean suggestions: delete test instrumentation
* Fix tests
* Fix test
`foo` has a genuine match: `for`
* Improve tests
* Add "space" key to bind in vi normal mode
Implements #6586
No special logic to prevent you from binding it in other modes!
Needs a separate change to reedline to make it available in the default
listing of `keybindings list`.
* Update reedline to report the available `space`
Pulls in nushell/reedline#486
* Apply clippy fix to avoid extra allocation
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:82:9
|
82 | long_desc.push_str(&format!("\n{G}Subcommands{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::format-push-string` implied by `-D warnings`
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:96:9
|
96 | long_desc.push_str(&format!("\n{G}Parameters{RESET}:\n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:128:9
|
128 | long_desc.push_str(&format!("\n{}Examples{}:", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: `format!(..)` appended to existing `String`
--> crates/nu-engine/src/documentation.rs:202:5
|
202 | long_desc.push_str(&format!("\n{}Flags{}:\n", G, RESET));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using `write!` to avoid the extra allocation
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
error: could not compile `nu-engine` due to 4 previous errors
* Apply clippy fix to avoid deref on an immutable reference
error: deref on an immutable reference
--> crates/nu-command/src/dataframe/eager/sql_context.rs:188:77
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&*select_stmt)?,
| ^^^^^^^^^^^^^
|
= note: `-D clippy::borrow-deref-ref` implied by `-D warnings`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
help: if you would like to reborrow, try removing `&*`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(select_stmt)?,
| ~~~~~~~~~~~
help: if you would like to deref, try using `&**`
|
188 | SetExpr::Select(select_stmt) => self.execute_select(&**select_stmt)?,
| ~~~~~~~~~~~~~~
error: deref on an immutable reference
--> crates/nu-command/src/database/values/dsl/expression.rs:252:15
|
252 | match &*expr {
| ^^^^^^ help: if you would like to reborrow, try removing `&*`: `expr`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
error: could not compile `nu-command` due to 2 previous errors
* trim overlay name
* format
* Update tests/overlays/mod.rs
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
* cleanup
* new tests
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
* Disable clickable links when we can't get metadata of files
Fixes#6498
* Refactor path name rendering related code
* Make clickable links smarter
* Remove unneeded clone
* Return early if `use_ls_colors` is disabled
* default to if cellpath not found
* fmt
* add test
* fix test
* fix clippy
* move behaviour behind `-i` flag
* prevent any possibility of an unspanned error
* ignore all errors
* seperate testes
* fmt
* Add support for Arrow IPC file format
Add support for Arrow IPC file format to dataframes commands. Support
opening of Arrow IPC-format files with extension '.arrow' or '.ipc' in
the open-df command. Add a 'to arrow' command to write a dataframe to
Arrow IPC format.
* Add unit test for open-df on Arrow
* Add -t flag to open-df command
Add a `--type`/`-t` flag to the `open-df` command, to explicitly specify
the type of file being used. Allowed values are the same at the set of
allowed file extensions.
* Initialize join.rs as a copy of collect.rs
* Evolve StrCollect into StrJoin
* Replace 'str collect' with 'str join' everywhere
git ls-files | lines | par-each { |it| sed -i 's,str collect,str join,g' $it }
* Deprecate 'str collect'
* Revert "Deprecate 'str collect'"
This reverts commit 959d14203e.
* Change `str collect` help message to say that it is deprecated
We cannot remove `str collect` currently (i.e. via
`nu_protocol::ShellError::DeprecatedCommand` since a prominent project
uses the API:
b85542c31c/src/virtualenv/activation/nushell/activate.nu (L43)
* Add a 'commandline' command for manipulating the current buffer
from `executehostcommand` keybindings. Inspired by fish:
https://fishshell.com/docs/current/cmds/commandline.html
* Update to development reedline
Includes nushell/reedline#472
Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
* Improve wording around `all` and `any`
The role of the `predicate` for `all` and `any` was not as clear.
See #6499
* type-o
* type-o
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Rename `all?`, `any?` and `empty?` to `all`, `any` and `is-empty` for sake of simplicity and consistency.
- More understandable for newcomers, that these commands are no special to others.
- `?` syntax did not really aprove readability. For me it made it worse.
- We can reserve `?` syntax for any other nushell feature.
* Add source-env test for dynamic path
* Use correct module ID for env overlay imports
* Remove parser check from "overlay list"
It would cause unnecessary errors from some inner scope if some
overlay module was also defined in some inner scope.
* Restore Cargo.lock back
* Remove comments
* add new function to remove data at a cellpath; allow reject to use cellpath
* add tests
* fmt
* fix clippt
* get it working properly with lists of records
* fix clippy, hopefully
* fix clippy, hopefully 2
* remove unnecessary FlatShape
* add proptest
* remove files that belonged in another PR
* more tests, more chars
* add exception for parser error unrelated ot PR
* nu-path: use 'linux' code on all non-macOS unix
* nu-command: cfg() the Ps command to platforms it's actually implemented on
* nu-system: cfg() the Ps test to the platforms Ps is implemented on
* start working on source-env
* WIP
* Get most tests working, still one to go
* Fix file-relative paths; Report parser error
* Fix merge conflicts; Restore source as deprecated
* Tests: Use source-env; Remove redundant tests
* Fmt
* Respect hidden env vars
* Fix file-relative eval for source-env
* Add file-relative eval to "overlay use"
* Use FILE_PWD only in source-env and "overlay use"
* Ignore new tests for now
This will be another issue
* Throw an error if setting FILE_PWD manually
* Fix source-related test failures
* Fix nu-check to respect FILE_PWD
* Fix corrupted spans in source-env shell errors
* Fix up some references to old source
* Remove deprecation message
* Re-introduce deleted tests
Co-authored-by: kubouch <kubouch@gmail.com>
* Test commands for proper names and search terms
Assert that the `Command.name()` is equal to `Signature.name`
Check that search terms are not just substrings of the command name as
they would not help finding the command.
* Clean up search terms
Remove redundant terms that just replicate the command name.
Try to eliminate substring between search terms, clean up where
necessary.
* Revert "Fix intermittent test crash (#6268)"
This reverts commit 555d9ee763.
* make a working version again
* try second impl
* add
* fmt
* check stdin is atty before acquire stdin
* add libc
* clean comment
* fix typo
* Add hide-env to hide env vars; Cleanup tests
Also, there were some old unalias tests that I converted to hide.
* Add missing file
* Re-enable hide for env vars
* Fix test
* Rename did you mean error back
It was causing random tests to break
* Add decimals to int when using `into string --decimals`
* Add tests for `into string` when converting int with `--decimals`
* Apply formatting
* Merge `into_str` test files
* Comment out unused code and add TODOs
* Use decimal separator depending on system locale
* Add test helper to run closure in different locale
* Add tests for int-to-string conversion using different locales
* Add utils function to get system locale
* Add panic message when locking mutex fails
* Catch and resume panic later to prevent Mutex poisoning when test fails
* Move test to `nu-test-support` to keep `nu-utils` free of `nu-*` dependencies
See https://github.com/nushell/nushell/pull/6085#issuecomment-1193131694
* Rename test support fn `with_fake_locale` to `with_locale_override`
* Move `get_system_locale()` to `locale` module
* Allow overriding locale with special env variable (when not in release)
* Use special env var to override locale during testing
* Allow callback to return a value in `with_locale_override()`
* Allow multiple options in `nu!` macro
* Allow to set locale as `nu!` macro option
* Use new `locale` option of `nu!` macro instead of `with_locale_override`
Using the `locale` options does not lock the `LOCALE_OVERRIDE_MUTEX`
mutex in `nu-test-support::locale_override` but instead calls the `nu`
command directly with the `NU_LOCALE_OVERRIDE` environment variable.
This allows for parallel test excecution.
* Fix: Add option identifier for `cwd` in usage of `nu!` macro
* Rely on `Display` trait for formatting `nu!` macro command
- Removed the `DisplayPath` trait
- Implement `Display` for `AbsolutePath`, `RelativePath` and
`AbsoluteFile`
* Default to locale `en_US.UTF-8` for tests when using `nu!` macro
* Add doc comment to `nu!` macro
* Format code using `cargo fmt --all`
* Pass function directly instead of wrapping the call in a closure
https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
* Pass function to `or_else()` instead of calling it inside `or()`
https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
* Fix: Add option identifier for `cwd` in usage of `nu!` macro
* add -p for path expand, so it doesn't follow symlink
* fix arg name
* rename from no-dereferenct to no-follow-link
* rename from no-follow-link to no-symlink, and change short -p to -n
* follow strict first
* fix
* simplify test
* fix clippy
* fix test on windows