Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8368 +/- ##
=======================================
Coverage 68.25% 68.25%
=======================================
Files 620 620
Lines 99355 99355
=======================================
Hits 67813 67813
Misses 31542 31542 |
|
Nice add. Just initial thoughts. There are a few changes here that do not allow this to be a drop-in replacement for our
Generally speaking, this is a great start and covers most of the points we'd want to cover. Thanks for this submission! |
|
I wasn't aiming for a drop in replacement (although that would be technically feasible). While I was playing around with idea of how to write a stdlib package, I was also playing around with the user model of working in multiple directories at once. For me, and I'm just riffing here, the problem with But I'm sure we can come up with a set of names that strike the right chord! You're right about the |
|
Just my two cents, I'd prefer to have a drop in replacement first and then tweak the naming later. Also, just for your information, shells used to be more full feature. We allowed you to enter files and do ls, cd, etc within a file structure. It was cool but not super practical. So, you're right that we've lost some functionality and may be ready for new command naming. Let's see what others think. |
|
Recent commits finalize with stdlib (you can get the commands by Remaining to do is deprecating I'll take off the "draft" tag at that point and be ready to merge. |
|
I don't really mind the new naming since it's based on some state-of-the art, as you mentioned. But maybe we can add the |
|
Can't really add aliases to default config till we can rely on the |
|
tracking #8311 for refinement of stdlib structure. This PR is dependent on choices made there. |
amtoine
left a comment
There was a problem hiding this comment.
thanks a lot that's great 👍
i think there is not real format standard right now for nushell (and i really need to work on nufmt 👀) but here is a diff i think would improve a bit the library, only whitespaces and minor things 😉
diff --git a/crates/nu-utils/standard_library/dirs.nu b/crates/nu-utils/standard_library/dirs.nu
index dedf81d63..1c989c9d9 100644
--- a/crates/nu-utils/standard_library/dirs.nu
+++ b/crates/nu-utils/standard_library/dirs.nu
@@ -9,8 +9,8 @@ export-env {
# Add one or more directories to the list.
# PWD becomes first of the newly added directories.
export def-env "add" [
- ...paths: string # directory or directories to add to working list
- ] {
+ ...paths: string # directory or directories to add to working list
+] {
mut abspaths = []
for p in $paths {
if ($p | path type) != 'dir' {
@@ -28,23 +28,28 @@ export def-env "add" [
# Advance to the next directory in the list or wrap to beginning.
export def-env "next" [
- N:int = 1 # number of positions to move.
+ N: int = 1 # number of positions to move.
] {
- _fetch $N
+ _fetch $N
}
# Back up to the previous directory or wrap to the end.
export def-env "prev" [
- N:int = 1 # number of positions to move.
+ N: int = 1 # number of positions to move.
] {
- _fetch (-1 * $N)
+ _fetch (-1 * $N)
}
# Drop the current directory from the list, if it's not the only one.
# PWD becomes the next working directory
export def-env "drop" [] {
if ($env.DIRS_LIST | length) > 1 {
- let-env DIRS_LIST = (($env.DIRS_LIST | take $env.DIRS_POSITION) | append ($env.DIRS_LIST | skip ($env.DIRS_POSITION + 1)))
+ let-env DIRS_LIST = (
+ ($env.DIRS_LIST | take $env.DIRS_POSITION)
+ | append (
+ $env.DIRS_LIST | skip ($env.DIRS_POSITION + 1)
+ )
+ )
}
_fetch 0
@@ -55,7 +60,7 @@ export def-env "show" [] {
mut out = []
for $p in ($env.DIRS_LIST | enumerate) {
$out = ($out | append [
- [active, path];
+ [active, path];
[($p.index == $env.DIRS_POSITION), $p.item]
])
}
@@ -63,18 +68,15 @@ export def-env "show" [] {
$out
}
-
-
# fetch item helper
-def-env _fetch [
- offset: int, # signed change to position
+def-env _fetch [
+ offset: int # signed change to position
] {
# nushell 'mod' operator is really 'remainder', can return negative values.
- # see: https://stackoverflow.com/questions/13683563/whats-the-difference-between-mod-and-remainder
+ # see: https://stackoverflow.com/questions/13683563/whats-the-difference-between-mod-and-remainder
let pos = ($env.DIRS_POSITION + $offset + ($env.DIRS_LIST | length)) mod ($env.DIRS_LIST | length)
# echo $"at ($pos); item is: ($env.DIRS_LIST | get $pos)"
let-env DIRS_POSITION = $pos
cd ($env.DIRS_LIST | get $pos )
}
-
\ No newline at end of fileand now let's test it 😏
There was a problem hiding this comment.
some feedback i have 😋
- i think it's not related to your work but here's what i get 🤔
>_ use std.nu
>_ help std dirs
Error: nu::parser::not_found
× Not found.
╭─[entry #2:1:1]
1 │ help std dirs
· ────┬───
· ╰── did not find anything under this name
╰────but
>_ help std
std.nu, `used` to load all standard library components
Module: std
Exported commands:
assert (std assert), assert eq (std assert eq), assert ne (std assert ne), dirs add (std dirs add), dirs drop (std dirs drop), dirs next (std dirs next), dirs prev (std dirs prev), dirs show (std dirs show), match (std match), path add (std path add)
This module does not export environment.and i cannot
>_ use std.nu dirs
Error: nu::parser::export_not_found
× Export not found.
╭─[entry #7:1:1]
1 │ use std.nu dirs
· ──┬─
· ╰── could not find imports
╰────🤔
otherwise, this is quite cool, i've played a bit with it and it looks to be working fine for now 🥳
so left to be done
- ❌ the few changes propositions i've come up with
- ✔️ the
path expandbug - ✔️ the tests in
tests.nu
|
(sorry, I don't know how to reply directly to your comment above about Maybe it's a bug in how 〉use ~/src/rust/nushell/crates/nu-utils/standard_library/std.nu
-------------------------------------------- /home/bobhy/src/rust/nushell --------------------------------------------
〉help std
std.nu, `used` to load all standard library components
Module: std
Exported commands:
assert (std assert), assert eq (std assert eq), assert ne (std assert ne), dirs add (std dirs add), dirs drop (std dirs drop), dirs next (std dirs next), dirs prev (std dirs prev), dirs show (std dirs show), match (std match), path add (std path add)
This module does not export environment.
-------------------------------------------- /home/bobhy/src/rust/nushell --------------------------------------------
〉help std dirs
Error: nu::parser::not_found
× Not found.
╭─[entry #32:1:1]
1 │ help std dirs
· ────┬───
· ╰── did not find anything under this name
╰────
-------------------------------------------- /home/bobhy/src/rust/nushell --------------------------------------------
〉help std dirs add
Add one or more directories to the list.
PWD becomes first of the newly added directories.
Usage:
> std dirs add ...(paths)
Flags:
-h, --help - Display the help message for this command
Parameters:
...paths <string>: directory or directories to add to working list
|
|
I believe I've picked up all the (very good!) suggestions, and added credible tests (which all pass). But I do believe the |
amtoine
left a comment
There was a problem hiding this comment.
a few little things i think would improve the module and the tests right away 😉
apart from that, i like this a lot and the tests pass 👌
| } | ||
|
|
||
| cd $base_path | ||
| cd .. |
There was a problem hiding this comment.
you do not need to undo the cds in a regular def function, 'cause the PWD does not change outside the scope of the function.
you might be familiar with subshells in bash where
# here you in some initial-place/
{
cd somewhere
# do something in somewhere/
}
# and you're back to initial-place/ without any `cd`ing backThere was a problem hiding this comment.
Is the localized CD true of changes within any closure (like a try/catch or if/then), or only within scope of function body?
I was also concerned that a failing test might leave the working directory indeterminate, which might make the directory cleanup at the end unreliable. So I think I have to CD into the parent directory before I try to rm -r the temporary directories, since there is some risk I might still have working directory set to one of the directories I'm trying to delete.
And really, the extra CD is cheap insurance in a test, it's not mainline code... I want to leave it as is.
There was a problem hiding this comment.
this disk directory might be not trivial to work with 🤔
There was a problem hiding this comment.
I would agree with @bobhy here that we probably should play it defensive for now. It is not totally unprecedented that our semantics in this area have changed. And if we can keep the blast radius minimal for stuff like that we get a little peace of mind.
There was a problem hiding this comment.
but what about just putting all these directories inside $nu.temp-path instead? 🤔
that would solve the issue of cleaning them => they would be at next reboot for example and the amount of things being generated is minimal
…arvest; whitespace patrol
|
I've maintained my local assert in the test, will refactor this out when the official one lands, in a new PR. |
that sounds great, when #8405 is merged then 👍 the code is nice, the tests pass, let's wait for the core team to approve this 😉 |
|
Looks fun to play with, let's do it! |
|
🥳 |
Related to #8368. # Description as planned in #8311, the `enter`, `shells`, `g`, `n` and `p` commands have been re-implemented in pure-`nushell` in the standard library. this PR removes the `rust` implementations of these commands. - all the "shells" tests have been removed from `crates/nu-commnand/tests/commands/` in 2cc6a82, except for the `exit` command - `cd` does not use the `shells` feature in its source code anymore => that does not change its single-shell behaviour - all the command implementations have been removed from `crates/nu-command/src/shells/`, except for `exit.rs` => `mod.rs` has been modified accordingly - the `exit` command now does not compute any "shell" related things - the `--now` option has been removed from `exit`, as it does not serve any purpose without sub-shells # User-Facing Changes users may now not use `enter`, `shells`, `g`, `n` and `p` now they would have to use the standard library to have access to equivalent features, thanks to the `dirs.nu` module introduced by @bobhy in #8368 # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - ⚫ `toolkit test` - ⚫ `toolkit test stdlib` # After Submitting the website will have to be regenerated to reflect the removed commands 👍
Description
Prototype replacement for
enter,n,p,exitbuilt-ins implemented as scripts in standard library.MVP-level capabilities (rough hack), for feedback please. Not intended to merge and ship as is.
(Description of your pull request goes here. Provide examples and/or screenshots if your changes affect the user experience.)
User-Facing Changes
New command in standard library
Tests + Formatting
Haven't even looked at stdlib
tests.nuyet.Other todos:
use .../standard_library/std.nuto load this module without having to put all the source instd.nu?std dirs ...?enterandexitdo that this should do? Then deprecate those commands.Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspaceto check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.