* Add rest arg to def
This commit applied adds the ability to define the rest parameter of a def
command. It does not implement the functionality to expand the rest argument in
a user defined def function.
The rest argument has to be exactly worded "...rest".
Example after this PR is applied:
file test.nu
```shell
def my_command [
...rest:int # My rest arg
] {
echo 1 2 3
}
```
```shell
> source test.nu
> my_command -h
Usage:
> my_command ...args {flags}
Parameters:
...args: My rest arg
Flags:
-h, --help: Display this help message
```
* Fix space in help on wrong side
* Remove wrong test case
* Parse long and shortflags without space correctly
* Update param_flag_list.rs
* Update param_flag_list.rs
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
* move commands, futures.rs, script.rs, utils
* move over maybe_print_errors
* add nu_command crate references to nu_cli
* in commands.rs open up to pub mod from pub(crate)
* nu-cli, nu-command, and nu tests are now passing
* cargo fmt
* clean up nu-cli/src/prelude.rs
* code cleanup
* for some reason lex.rs was not formatted, may be causing my error
* remove mod completion from lib.rs which was not being used along with quickcheck macros
* add in allow unused imports
* comment out one failing external test; comment out one failing internal test
* revert commenting out failing tests; something else might be going on; someone with a windows machine should check and see what is going on with these failing windows tests
* Update Cargo.toml
Extend the optional features to nu-command
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
* Put parse_definition related funcs into own module
* Add failing lexer test
* Implement Parsing of definition signature
This commit applied changes how the signature of a function is parsed. Before
there was a little bit of "quick-and-dirty" string-matching/parsing involved.
Now, a signature is a little bit more properly parsed.
The grammar of a definition signature understood by these parsing-functions is
as follows:
`[ (parameter | flag | <eol>)* ]`
where
parameter is:
`name (<:> type)? (<,> | <eol> | (#Comment <eol>))?`
flag is:
`--name (-shortform)? (<:> type)? (<,> | <eol> | (#Comment <eol>))?`
(Note: After the last item no <,> has to come.)
Note: It is now possible to pass comments to flags and parameters
Example:
[
d:int # The required d parameter
--x (-x):string # The all powerful x flag
--y (-y):int # The accompanying y flag
]
(Sadly there seems to be a bug (Or is this expected behaviour?) in the lexer, because of which `--x(-x)` would
be treated as one baseline token and is therefore not correctly recognized as 2. For
now a space has to be inserted)
During the implementation of the module, 2 question arose:
Should flag/parameter names be allowed to be type names?
Example case:
```shell
def f [ string ] { echo $string }
```
Currently an error is thrown
* Fix clippy lints
* Remove wrong comment
* Add spacing
* Add Cargo.lock
* move basic_shell_manager to nu-engine
* move basic_evaluation_context to nu-engine
* fix failing test in feature which commands/classified/external.rs
We split off the evaluation engine part of nu-cli into its own crate. This helps improve build times for nu-cli by 17% in my tests. It also helps us see a bit better what's the core engine portion vs the part specific to the interactive CLI piece.
There's more than can be done here, but I think it's a good start in the right direction.
* Obay precedence rules in which; Fix#2875
Before which did not obay the precedence of alias before def commands.
Furthermore, `which -a echo` would only report either an alias or a def command or an
internal command with the provided name. Not all.
With this commit applied its fixed :)
Example:
```shell
/home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi}
/home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo
hi
/home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo
───┬──────┬──────────────────────────┬─────────
# │ arg │ path │ builtin
───┼──────┼──────────────────────────┼─────────
0 │ echo │ Nushell custom command │ No
1 │ echo │ Nushell built-in command │ Yes
2 │ echo │ /usr/bin/echo │ No
───┴──────┴──────────────────────────┴─────────
/home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there
/home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo
hi there
/home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo
───┬──────┬──────────────────────────┬─────────
# │ arg │ path │ builtin
───┼──────┼──────────────────────────┼─────────
0 │ echo │ Nushell alias │ No
1 │ echo │ Nushell custom command │ No
2 │ echo │ Nushell built-in command │ Yes
3 │ echo │ /usr/bin/echo │ No
───┴──────┴──────────────────────────┴─────────
```
* Fix clippy lint
* Fix vec always Some even if empty
This commit applied adds comments preceding a command to the LiteCommands new
field `comments`.
This can be usefull for example when defining a function with `def`. Nushell
could pick up the comments and display them when the user types `help my_def_func`.
Example
```shell
def my_echo [arg] { echo $arg }
```
The LiteCommand def will now contain the comments `My echo` and `It's much
better :)`.
The comment is not associated with the next command if there is a (or multiple) newline
between them.
Example
```shell
echo 42
```
This new functionality is similar to DocStrings. One might introduce a special
notation for such DocStrings, so that the parser can differentiate better
between discardable comments and usefull documentation.
* Update dependencies
* 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).
* Fix rustfmt
* Update lock
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Jonathan Turner <jonathan.d.turner@gmail.com>
* Adding coerce filesize functionality to math avg median
* Updating initial value creating in Math Summation Reducer
* Update reducers.rs
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
* update the rust-embed dependency of nu-cli to 5.8.0 and undo the version pin of syn now that rust-embed-impl has been fixed
* unpin syn version in chart plugin
* Display aliases and custom commands in which; Fix#2810
Example output of nu after the commit is applied:
```shell
/home/leo/repos/nushell(feature/which_inspect_alias)> def docker-ps [] { docker ps --format '{{json .}}' | from json -o }
/home/leo/repos/nushell(feature/which_inspect_alias)> which docker-ps
───┬───────────┬────────────────────────┬─────────
# │ arg │ path │ builtin
───┼───────────┼────────────────────────┼─────────
0 │ docker-ps │ nushell custom command │ No
───┴───────────┴────────────────────────┴─────────
/home/leo/repos/nushell(feature/which_inspect_alias)> alias d = gid pd
/home/leo/repos/nushell(feature/which_inspect_alias)> which d
───┬─────┬───────────────┬─────────
# │ arg │ path │ builtin
───┼─────┼───────────────┼─────────
0 │ d │ nushell alias │ No
───┴─────┴───────────────┴─────────
```
* Update documentation
* nu-stream is building on its own, now clean up Cargo.toml
* replace the stream crate in nu-cli
* cc
* since we moved stream out of the nu-cli crate and into its own crate we need to remove pub(crate) and just make it pub
* clean up the prelude and hand merge everything together
* clean up Cargo.tom
* cargo fmt along with Cargo.lock
* Begin allowing comments and multiline scripts.
* clippy
* Finish moving to groups. Test pass
* Keep going
* WIP
* WIP
* BROKEN WIP
* WIP
* WIP
* Fix more tests
* WIP: alias starts working
* Broken WIP
* Broken WIP
* Variables begin to work
* captures start working
* A little better but needs fixed scope
* Shorthand env setting
* Update main merge
* Broken WIP
* WIP
* custom command parsing
* Custom commands start working
* Fix coloring and parsing of block
* Almost there
* Add some tests
* Add more param types
* Bump version
* Fix benchmark
* Fix stuff
v0.29.0 and earlier versions of `uom` fail to compile on nightly because
of now-ambiguous trait bounds. The issue was corrected in v0.30.0 of
`uom`. `uom` and `heim` dependencies have been updated to the
latest version to include this fix and allow nushell to compile on
nightly.
Co-authored-by: Boutin, Michael <mjboutin@ecolab.com>
* updated & added date related commands based on the new design
* added proper error handling when date format string is invalid
* fixed format issue
* fixed an issue caused due to the change in primitive Date type
* added `date list-timezone` command to list all supported time zones and updated `date to-timezone` accordingly
This makes the errors slightly better. It took me a while to realize I was missing the `--raw` flag.
```
open "data.csv" | from csv --separator ';'
```
error: Could not parse as CSV split by ',' (Line 1: expected 1 fields, found 14)
┌─ shell:1:1
│
1 │ open "data.csv" | from csv --separator ';'
│ ^^^^ ------------------------------------------------- value originates from here
│ │
│ input cannot be parsed as CSV split by ','. Sample input:
Name;Data
Ugly;row
AnotherUgly;row
I think this still needs some refinement. Maybe we don't want to show
the separator all the time, omitting the defaults or the separator
on other formats.
* Bump Rustyline to 7.0.0
* Append history instead of always save
* Add associated type to Hinter
* Convert to using Rustyline KeyEvent
* Use AcceptOrInsertLine as struct
* Cargo fmt
* Make convert_keyevent pub
* Better naming for RL conversion
* WIP try testing hash command
Ensure test worked
fmt
WIP get it working for other types of base64
Use optional named arg
WIP
* rebased and refactored a little with encoding and decoding
Fix some typos
Add some more charactersets
refactor several args into the encoding config struct and fix character_set arg. It needs to match the field
Add main hash command so it can be found via help
Added tests for running the whole pipeline
* add test case to cover invalid character sets
* clippy and fmt
* Add string argument support for path subcommands
* Add --replace option to 'path extension' command
* Add examples of replacing for path extension
* Refactor path extension and its example
* Add replacement functionality to path basename
* Refactor path subcommands to support more args
This adds a lot of redundancy to non-relevant subcommands such as type,
exists or expand.
* Add replace and num_levels options to path dirname
* Rename num_levels option to num-levels
* Remove commented code
* Clean up path basename
* Fix path dirname description
* Add path filestem opts; Rename extension -> suffix
* Add prefix option and examples to path filestem
* Fix broken num-levels of path dirname
* Fix failing example test of path filestem
* Fix failing test of path extension
* Formatting
* Add Windows-specific path subcommand examples
`path expand` is still broken but otherwise seems to fix all examples
on Windows
* Fix weird path expand on Windows
Also disable example tests for path expand. Failed caconicalization
(e.g., due to path not existing) returns the original path so the
examples always fail.
* Formatting
* Return path datatype when appropriate
* Do not append empty remainder to path dirname
* Add tests for path subcommands
* Formatting
* Revisit path subcommand description strings
* Apply clippy suggestions; Formatting
* Remove problematic test checking '~' expansion
Wouldn't run on minimal due to useing optional dependency.
The test success was also deending on the presence of home dir on the
testing machine which might not be completely robust.
* Add missing newline to file