Commit Graph

555 Commits

Author SHA1 Message Date
Yehuda Katz
34292b282a Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.

The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.

As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.

For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.

This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).

The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.

This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.

By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.

In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:03:24 -07:00
Patrick Meredith
738675259e Improve test so that it should work on Windows 2019-08-26 21:26:49 -04:00
Patrick Meredith
87a99bbabf Implement to-bson 2019-08-26 20:07:59 -04:00
Dirkjan Ochtman
b77effa434 Fix formatting with cargo fmt 2019-08-26 20:19:05 +02:00
Andrés N. Robalino
8940e57cf3 mark #[test] back. (deleted and reverting it from.. 12e38063) 2019-08-25 21:50:55 -05:00
Andrés N. Robalino
12e3806349
Merge pull request #415 from androbtech/fromto-refact
[from|to]csv additions/refactoring.
2019-08-25 12:56:28 -05:00
Jonathan Turner
dda4a707a7
Merge pull request #421 from ramonsnir/reverse
add reverse
2019-08-26 05:41:07 +12:00
Andrés N. Robalino
0e14ba86ae [from|to]csv additions/refactoring.
Introduced flag to tell `from-to` / `to-csv` whether we want headers parsed and/or written.
2019-08-25 12:32:08 -05:00
Patrick Meredith
3c89cb7e98 Remove test that refuses to pass on Windows (it's just a minor formatting issue) 2019-08-25 12:25:40 -04:00
Ramon Snir
9735c3fcea
add reverse 2019-08-25 12:14:17 -04:00
Patrick Meredith
376809aa2a Normalize strings for bson tests 2019-08-25 11:43:15 -04:00
Patrick Meredith
e9673c31ea Remove redundant test 2019-08-25 09:50:25 -04:00
Patrick Meredith
a3b4d47b4e Finish last few types and add tests 2019-08-25 09:50:25 -04:00
Jonathan Turner
9c4f94fed5
Merge pull request #402 from ijt/add-last-command
Add `last` filter
2019-08-25 13:00:13 +12:00
Issac Trotts
45d514a4cb sort to get test to pass on linux 2019-08-24 17:21:09 -07:00
Issac Trotts
108f66941b add last command 2019-08-24 15:01:30 -07:00
Issac Trotts
af2439e880 add test 2019-08-24 14:56:56 -07:00
Dmitry Starostin
19772f82aa
Add --reverse option for sort-by 2019-08-25 00:11:38 +03:00
Andrés N. Robalino
8b79b28971 mkdir can take multiple directories or multiple directory hierachies and wil create them as required. 2019-08-21 07:07:37 -05:00
Andrés N. Robalino
8c1d4ed91a sidestep 'enter' integration test failure for files. 2019-08-20 08:01:02 -05:00
Andrés N. Robalino
0f28719564 mv -> More organized method definitions. 2019-08-20 07:35:41 -05:00
Andrés N. Robalino
11095860c8 rm fully operational and error surveyd. 2019-08-20 06:22:11 -05:00
Andrés N. Robalino
308323426d Covered enter's ability to enter files other than filesystems. 2019-08-20 03:11:33 -05:00
Jonathan Turner
51ec48f357 Update enter test 2019-08-20 04:40:47 +12:00
Jonathan Turner
953d28ef74 Fix push/pop for shell manager 2019-08-19 20:07:55 +12:00
Andrés N. Robalino
5dd20850b5 Refactoring and unwrap cleanup beginnings. 2019-08-18 20:28:55 -05:00
Yehuda Katz
0dc4b2b686 Add support for external escape valve (^dir)
This commit makes it possible to force nu to treat a command as an external command by prefixing it with `^`. For example `^dir` will force `dir` to run an external command, even if `dir` is also a registered nu command.

This ensures that users don't need to leave nu just because we happened to use a command they need.

This commit adds a new token type for external commands, which, among other things, makes it pretty straight forward to syntax highlight external commands uniquely, and generally to treat them as special.
2019-08-15 15:18:18 -07:00
Andrés N. Robalino
024f0915a3 Shellring traversal and filesystem environment retention per session confirmed. 2019-08-15 02:10:33 -05:00
Andrés N. Robalino
75e3c6f547 copies_expected -> expected. Use expected as test dirname expectation outcomes from now on. 2019-08-14 16:05:35 -05:00
Andrés N. Robalino
121237ee4b Reverted test removal from (dfcbaed) 2019-08-14 15:55:26 -05:00
Andrés N. Robalino
154063013f mv introduced. \¡Viva\! 2019-08-14 15:29:05 -05:00
Andrés N. Robalino
dfcbaed1c6 More descriptive test playground names for commands other than the basic ones. 2019-08-14 15:29:05 -05:00
Andrés N. Robalino
278de0e517 cp refactoring. 2019-08-14 15:29:05 -05:00
Jonathan Turner
6cf3dc92fc Add support for utf16 files 2019-08-12 16:11:42 +12:00
Andrés N. Robalino
fc38603de8 Test sample changed to check behavior with strings on different operating systems. 2019-08-11 13:18:42 -05:00
Andrés N. Robalino
cee2f5207e Str plugin: replace & find-replace. 2019-08-11 12:46:14 -05:00
Andrés N. Robalino
21ab65979f Covered the remaining semver flags for inc plugin. 2019-08-10 06:04:13 -05:00
Andrés N. Robalino
e744237451 Clean up. 2019-08-10 05:56:47 -05:00
Andrés N. Robalino
5372463b37 Extract tests. 2019-08-10 04:40:32 -05:00
Andrés N. Robalino
cb4b2e6116 Inc refactoring. More tests. 2019-08-10 04:38:28 -05:00
Andrés N. Robalino
5bfa2cc4b8 cp wildcard already supported (documented with test) 2019-08-10 04:32:27 -05:00
Jonathan Turner
83030094e0 All tests pass 2019-08-09 17:36:43 +12:00
Jonathan Turner
aadacc2d36 Merge master 2019-08-09 16:51:21 +12:00
Jonathan Turner
b815768166 Fix test 2019-08-09 05:53:28 +12:00
Andrés N. Robalino
ba6d62ea0c mkdir creates intermediary directories as required (the default). --create-all/--deep flag removed. 2019-08-07 14:38:00 -05:00
Andrés N. Robalino
50393bdf42 Make more visible the strategies for figuring out where to copy files. 2019-08-07 13:42:52 -05:00
Andrés N. Robalino
e0bacaaf37 clean up. more cp. mkdir. more test coverage. fixes.
- Introduced mkdir.
- Minor more labelled error improvements.
- Fix to avoid leaking child zombies.
- cp improvements.
- Introduced mkdir.
2019-08-07 13:28:46 -05:00
Andrés N. Robalino
c8b5329c5c mkdir. 2019-08-07 13:24:20 -05:00
Andrés N. Robalino
1b7dd52713 Tests pass. 2019-08-07 13:23:02 -05:00
Andrés N. Robalino
b38d54e033 Dont let Nu childs become zombies. 2019-08-07 13:18:02 -05:00
Yehuda Katz
fc173c46d8 Restructuring 2019-08-02 12:15:07 -07:00
Jonathan Turner
4821707f96 Test for external quoted strings 2019-08-03 04:33:52 +12:00
Andrés N. Robalino
7a76998f07 regular, * wildcard, and ? covered. 2019-08-02 05:31:15 -05:00
Jonathan Turner
aa54995326
Merge pull request #232 from androbtech/unit-tests-wip
Introduced to-int into str plugin and unit tests coverage along with it.
2019-08-02 13:06:30 +12:00
Andrés N. Robalino
1bc1bb6111 Glob paths can fail. Communicates the error if it happens. thanks (jonathandturner) 2019-08-01 16:55:49 -05:00
Andrés N. Robalino
375f311331 Wildcard support adventure starting with rm command. 2019-08-01 16:01:53 -05:00
Andrés N. Robalino
0893f89e89 More readable tests. 2019-08-01 04:28:49 -05:00
Andrés N. Robalino
610a91a658 Test coverage for pull #235 2019-08-01 03:31:41 -05:00
Andrés N. Robalino
a0890b551a strutils can also convert to an integer now. 2019-07-31 23:50:03 -05:00
Andrés N. Robalino
0b8bbd8637 Unit Testing WIP. 2019-07-31 23:46:59 -05:00
Andrés N. Robalino
7c4706ee50 Validation baseline. 2019-07-28 18:34:37 -05:00
Andrés N. Robalino
59dec999b8 string utils plugin baseline. 2019-07-28 02:01:32 -05:00
Jonathan Turner
e4797f8895 Add end_plugin and sum 2019-07-27 06:40:00 +12:00
Yehuda Katz
73deeb69db Clean up lint errors 2019-07-23 21:10:48 -07:00
Yehuda Katz
5a8e041a48 Tests pass! 2019-07-23 15:22:11 -07:00
Jonathan Turner
72384629fd
Merge pull request #205 from androbtech/cp_play
Introduced initial cp functionality.
2019-07-24 04:46:30 +12:00
Jonathan Turner
ec7d49b0d2 Add and edit functionality 2019-07-22 15:52:57 +12:00
Andrés N. Robalino
2da43f4b06 Introduced initial cp functionality. 2019-07-21 21:23:02 -05:00
Andrés N. Robalino
191dacdd8b Introduced conversion to csv command. 2019-07-21 02:08:05 -05:00
Jonathan Turner
c36c2a7b50 Switch from_csv to output rows 2019-07-20 18:44:21 +12:00
Jonathan Turner
08f6d29b79 Fix race condition in test 2019-07-20 13:18:27 +12:00
Andrés N. Robalino
895a1b2d72 Introduced ability to open csv documents. 2019-07-19 15:48:42 -05:00
Andrés N. Robalino
514da5bfa7 Can remove files and directories. 2019-07-18 05:21:24 -05:00
Jonathan Turner
0d6881383d Add some tests 2019-07-18 13:57:58 +12:00
Jonathan Turner
f10225e26b
Merge pull request #190 from jonathandturner/improved_open_url
Improved open url
2019-07-18 07:25:02 +12:00
Jonathan Turner
00b3106f05 Improve open URL. Format and remove warning in tests 2019-07-18 06:56:15 +12:00
Jonathan Turner
227fdddc12 Add yaml roundtrip test. Bump nu version 2019-07-18 05:51:53 +12:00
Andrés N. Robalino
f120ce63f7 Test cases not needed for now. 2019-07-16 16:47:01 -05:00
Andrés N. Robalino
6824c9c7a4 Sample data moved 2019-07-16 14:00:34 -05:00
Andrés N. Robalino
275126d76d Back to passing. Windows test failure needs more investigation. 2019-07-16 06:48:10 -05:00
Andrés N. Robalino
67a0606b6d Different test data for a format Nu does not recognize. 2019-07-16 06:31:53 -05:00
Andrés N. Robalino
c7531d6b3d Windows speaks \r 2019-07-16 05:58:40 -05:00
Andrés N. Robalino
5ca9d307c6 Integration tests refactoring and visibility in them. 2019-07-16 05:33:41 -05:00
Jonathan Turner
2f7f78094d Fix test 2019-07-14 17:09:07 +12:00
Jonathan Turner
dc8545ce10 Add a test for the plugins 2019-07-04 15:18:19 +12:00
Jonathan Turner
160074346f Fix units and add test 2019-06-24 19:59:23 +12:00
Jonathan Turner
9ae9beb94a WIP 2019-06-22 15:43:37 +12:00
Jonathan Turner
b4eb32f1db Touchups to external values 2019-06-19 17:51:24 +12:00
Jonathan Turner
cd9c1bb247
Update lines.txt 2019-06-18 16:44:38 +12:00
Jonathan Turner
2808337112 add lines and skip-while test 2019-06-18 15:45:50 +12:00
Jonathan Turner
1000ec21b5 Add .ini loading/saving 2019-06-16 18:43:40 +12:00
Jonathan Turner
7a332892bd Fixes for windows 2019-06-16 09:41:26 +12:00
Jonathan Turner
36edc059c8 Add missing test 2019-06-16 09:32:57 +12:00
Jonathan Turner
8cdd567b0e Rewrite README and do some touchups 2019-06-15 14:24:13 +12:00
Jonathan Turner
50fe77968f Fix test 2019-06-14 10:52:36 +12:00
Jonathan Turner
2752eb5d9b Update tests 2019-06-11 18:32:42 +12:00
Jonathan Turner
22f9126cf6 merge master and fix conflict 2019-06-11 18:27:19 +12:00
Jonathan Turner
7642541755 Add xml open support 2019-06-11 18:26:03 +12:00
Yehuda Katz
2b876da56f Some function stuff
It's not done, but honestly it's getting too tedious. I will need to
rethink how I'm doing it.
2019-06-10 13:11:55 -07:00
Jonathan Turner
3715da9328 Finish rename 2019-06-05 13:57:16 +12:00
Jonathan Turner
2a20192519 Fix up some warnings and move integration tests to correct dir 2019-06-03 15:48:58 +12:00
Jonathan Turner
0c2be40afc Fix integration tests for Linux 2019-06-03 13:26:29 +12:00
Jonathan Turner
f3d14aad48 Add more tests 2019-06-03 12:37:16 +12:00
Jonathan Turner
6fe9dc0bbf Add missing test file 2019-06-02 18:56:02 +12:00
Jonathan Turner
040c3a5e9c Add first integration test 2019-06-02 15:37:09 +12:00