nushell/crates/nu-command/tests/commands/mod.rs

64 lines
736 B
Rust
Raw Normal View History

mod append;
Autoenv rewrite, security and scripting (#2083) * Add args in .nurc file to environment * Working dummy version * Add add_nurc to sync_env command * Parse .nurc file * Delete env vars after leaving directory * Removing vals not working, strangely * Refactoring, add comment * Debugging * Debug by logging to file * Add and remove env var behavior appears correct However, it does not use existing code that well. * Move work to cli.rs * Parse config directories * I am in a state of distress * Rename .nurc to .nu * Some notes for me * Refactoring * Removing vars works, but not done in a very nice fashion * Refactor env_vars_to_delete * Refactor env_vars_to_add() * Move directory environment code to separate file * Refactor from_config * Restore env values * Working? * Working? * Update comments and change var name * Formatting * Remove vars after leaving dir * Remove notes I made * Rename config function * Clippy * Cleanup and handle errors * cargo fmt * Better error messages, remove last (?) unwrap * FORMAT PLZ * Rename whitelisted_directories to allowed_directories * Add comment to clarify how overwritten values are restored. * Change list of allowed dirs to indexmap * Rewrite starting * rewrite everything * Overwritten env values tracks an indexmap instead of vector * Refactor restore function * Untrack removed vars properly * Performance concerns * Performance concerns * Error handling * Clippy * Add type aliases for String and OsString * Deletion almost works * Working? * Error handling and refactoring * nicer errors * Add TODO file * Move outside of loop * Error handling * Reworking adding of vars * Reworking adding of vars * Ready for testing * Refactoring * Restore overwritten vals code * todo.org * Remove overwritten values tracking, as it is not needed * Cleanup, stop tracking overwritten values as nu takes care of it * Init autoenv command * Initialize autoenv and autoenv trust * autoenv trust toml * toml * Use serde for autoenv * Optional directory arg * Add autoenv untrust command * ... actually add autoenv untrust this time * OsString and paths * Revert "OsString and paths" This reverts commit e6eedf882498c1365ecfc899e5ec11bd83cb055c. * Fix path * Fix path * Autoenv trust and untrust * Start using autoenv * Check hashes * Use trust functionality when setting vars * Remove unused code * Clippy * Nicer errors for autoenv commands * Non-working errors * Update error description * Satisfy fmt * Errors * Errors print, but not nicely * Nicer errors * fmt * Delete accidentally added todo.org file * Rename direnv to autoenv * Use ShellError instead of Error * Change tests to pass, danger zone? * Clippy and errors * Clippy... again * Replace match with or_else * Use sha2 crate for hashing * parsing and error msg * Refactoring * Only apply vars once * if parent dir * Delete vars * Rework exit code * Adding works * restore * Fix possibility of infinite loop * Refactoring * Non-working * Revert "Non-working" This reverts commit e231b85570bcb3fc838f950e9f5004c6a7c5a2ac. * Revert "Revert "Non-working"" This reverts commit 804092e46a752266576b044401cc97c317e41f21. * Autoenv trust works without restart * Cargo fix * Script vars * Serde * Serde errors * Entry and exitscripts * Clippy * Support windows and handle errors * Formatting * Fix infinite loop on windows * Debugging windows loop * More windows infinite loop debugging * Windows loop debugging #3 * windows loop #4 * Don't return err * Cleanup unused code * Infinite loop debug * Loop debugging * Check if infinite loop is vars_to_add * env_vars_to_add does not terminate, skip loop as test * Hypothesis: std::env::current_dir() is messing with something * Hypothesis: std::env::current_dir() is messing with something * plz * make clippy happy * debugging in env_vars_to_add * Debbuging env_vars_to_add #2 * clippy * clippy.. * Fool clippy * Fix another infinite loop * Binary search for error location x) * Binary search #3 * fmt * Binary search #4 * more searching... * closing in... maybe * PLZ * Cleanup * Restore commented out functionality * Handle case when user gives the directory "." * fmt * Use fs::canonicalize for paths * Create optional script section * fmt * Add exitscripts even if no entryscripts are defined * All sections in .nu-env are now optional * Re-read config file each directory change * Hot reload after autoenv untrust, don't run exitscripts if untrusted * Debugging * Fix issue with recursive adding of vars * Thank you for finding my issues Mr. Azure * use std::env
2020-07-05 19:34:00 +02:00
mod autoenv;
mod autoenv_trust;
mod autoenv_untrust;
mod cal;
mod cd;
mod compact;
mod count;
mod cp;
mod def;
mod default;
mod drop;
mod each;
mod echo;
2020-10-06 12:21:20 +02:00
mod empty;
mod enter;
mod every;
mod first;
2020-10-14 11:36:11 +02:00
mod flatten;
mod format;
mod get;
mod group_by;
mod hash_;
mod headers;
mod histogram;
mod insert;
mod into_int;
mod keep;
mod last;
mod lines;
mod ls;
mod math;
mod merge;
mod mkdir;
2020-07-06 17:27:01 +02:00
mod move_;
mod open;
mod parse;
Path Command Enhancement Project (#2742) * 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
2020-11-24 10:18:38 +01:00
mod path;
mod prepend;
mod random;
mod range;
mod reduce;
2020-03-03 22:01:24 +01:00
mod rename;
mod reverse;
mod rm;
Table content rolling. (#3097) There are many use cases. Here we introduce the following: - The rows can be rolled `... | roll` (up) or `... | roll down` - Columns can be rolled too (the default is on the `left`, you can pass `... | roll column --opposite` to roll in the other direction) - You can `roll` the cells of a table and keeping the header names in the same order (`... | roll column --cells-only`) - Above examples can also be passed (Ex. `... | roll down 3`) a number to tell how many places to roll. Basic working example with rolling columns: ``` > echo '00000100' | split chars | each { str to-int } | rotate counter-clockwise _ | reject _ | rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 ───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬────── # │ bit1 │ bit2 │ bit3 │ bit4 │ bit5 │ bit6 │ bit7 │ bit8 ───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼────── 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 1 │ 0 │ 0 ───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴────── ``` We want to "shift" three bits to the left of the bitstring (four in decimal), let's try it: ``` > echo '00000100' | split chars | each { str to-int } | rotate counter-clockwise _ | reject _ | rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 | roll column 3 ───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬────── # │ bit4 │ bit5 │ bit6 │ bit7 │ bit8 │ bit1 │ bit2 │ bit3 ───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼────── 0 │ 0 │ 0 │ 1 │ 0 │ 0 │ 0 │ 0 │ 0 ───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴────── ``` The tables was rolled correctly (32 in decimal, for above bitstring). However, the *last three header names* look confusing. We can roll the cell contents only to fix it. ``` > echo '00000100' | split chars | each { str to-int } | rotate counter-clockwise _ | reject _ | rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 | roll column 3 --cells-only ───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬────── # │ bit1 │ bit2 │ bit3 │ bit4 │ bit5 │ bit6 │ bit7 │ bit8 ───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼────── 0 │ 0 │ 0 │ 1 │ 0 │ 0 │ 0 │ 0 │ 0 ───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴────── ``` There we go. Let's compute it's decimal value now (should be 32) ``` > echo '00000100' | split chars | each { str to-int } | rotate counter-clockwise _ | reject _ | roll column 3 --cells-only | pivot bit --ignore-titles | get bit | reverse | each --numbered { = $it.item * (2 ** $it.index) } | math sum 32 ```
2021-02-23 19:29:07 +01:00
mod roll;
90 degree table rotations (clockwise and counter-clockwise) (#3086) Also for 180 degree is expected. Rotation is not exactly like pivoting (transposing) for instance, given the following table: ``` > echo [[col1, col2, col3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] ───┬───────┬───────┬─────── # │ col1 │ col2 │ col3 ───┼───────┼───────┼─────── 0 │ cell1 │ cell2 │ cell3 1 │ cell4 │ cell5 │ cell6 ───┴───────┴───────┴─────── ``` To rotate it counter clockwise by 90 degrees, we can resort to first transposing (`pivot`) them adding a new column (preferably integers), sort by that column from highest to lowest, then remove the column and we have a counter clockwise rotation. ``` > echo [[col1, col2, col3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] | pivot | each --numbered { = $it.item | insert idx $it.index } | sort-by idx | reverse | reject idx ───┬─────────┬─────────┬───────── # │ Column0 │ Column1 │ Column2 ───┼─────────┼─────────┼───────── 0 │ col3 │ cell3 │ cell6 1 │ col2 │ cell2 │ cell5 2 │ col1 │ cell1 │ cell4 ───┴─────────┴─────────┴───────── ``` Which we can get easily, in this case, by doing: ``` > echo [[col1, col2, cel3]; [cell1, cell2, cell3] [cell4, cell5, cell6]] | rotate counter-clockwise ───┬─────────┬─────────┬───────── # │ Column0 │ Column1 │ Column2 ───┼─────────┼─────────┼───────── 0 │ col3 │ cell3 │ cell6 1 │ col2 │ cell2 │ cell5 2 │ col1 │ cell1 │ cell4 ───┴─────────┴─────────┴───────── ``` There are also many powerful use cases with rotation, it makes a breeze creating tables with many columns, say: ``` echo 0..12 | rotate counter-clockwise | reject Column0 ───┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬──────────┬──────────┬──────────┬────────── # │ Column1 │ Column2 │ Column3 │ Column4 │ Column5 │ Column6 │ Column7 │ Column8 │ Column9 │ Column10 │ Column11 │ Column12 │ Column13 ───┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼──────────┼──────────┼──────────┼────────── 0 │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │ 12 ───┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴──────────┴──────────┴──────────┴────────── ```
2021-02-22 12:56:34 +01:00
mod rotate;
mod save;
mod select;
mod semicolon;
mod skip;
mod sort_by;
mod split_by;
mod split_column;
2020-05-24 08:41:30 +02:00
mod split_row;
mod str_;
2020-02-18 21:54:32 +01:00
mod touch;
mod uniq;
mod update;
mod where_;
Obey precedence rules in which; Fix #2875 (#2885) * 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
2021-01-08 18:44:31 +01:00
mod which;
2020-05-06 05:56:31 +02:00
mod with_env;
mod wrap;