Repository navigation
Description
As a maintainer of nushell, I just want to say that we love the effort of uutils/coreutils. Good work y'all and please keep up this excellent work!
We love it so much that we really want to have a much tighter integration than just calling external executables. I myself, have started to experiment by using the uu_cp and uu_mv crates as internal nushell commands in this PR nushell/nushell#9463.
There are some rough edges that we'd need to work together on and I've tried to document different strategies in my PR. Without going into a lot of detail I'll just list a few things.
- Nushell doesn't use clap so working with command line arguments and the uu Options structs is interesting. Right now, I've kind of hacked it together where nushell checks params, then uu checks params, which isn't ideal, but it's a start.
- I've experimented with calling a command's uumain directly and passing args to it (and that can work), or rolling our own type of uumain. The benefit with rolling-our-own is we get the expected nushell "pretty" error messages. Error handling in general will need help and I'm not quite sure what to do here, specifically in regards to passing back a Span so we know where the error is.
- Streaming. Some uu_ commands stream output as output is generated, this is great and we'd need a way to hook into this output in order to consume it as nushell data structures that generate the nushell tabular or record output. I'm not really sure what is appropriate here.
In general, as you might guess, some things in coreutils may need to be exposed publicly, like command Options, to enable others, like nushell, to utilize them, and other things may need a different level of surgery in nushell or in coreutils.
One thing is for sure, we'd love to partner up and find a way forward because, let's be honest, dealing with some of these file-io and other commands is just difficult, and it would just be great to have one source of truth that works cross-platform like the uutils/coreutils.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
amtoine commentedon Jul 15, 2023
as a maintainer of Nushell myself, i totally support the initiative of @fdncred here 😊
sylvestre commentedon Jul 15, 2023
Sure, let's work together to make this happen!
dmatos2012 commentedon Jul 18, 2023
As a small small contributor of both nushell and coreutils, Id love to see this happen and would like to help in making this possible. :)
fdncred commentedon Jul 18, 2023
@dmatos2012 The easiest way for you (or anyone else that is interested) to help is to start playing with my nushell PR listed above. If you checkout my PR and compile it with
cargo build --features=nuuuthencpandmvwill be using the uutils version. You can play around and see that somemvsyntax does not work likemv a b c test/. It works in uutils mv but nushell doesn't allow it. This type of testing starts to reveal changes that will need to be made somewhere.The current task is to really to find a way forward. e.g. How do we handle spans, which nushell requires for errors? How do we handle parameter parsing? How do we handle streaming.
I started with uu_cp because there's not a lot of output with copying. I figured it may be an easy place to start. Then I went to uu_mv, which quickly revealed syntax that I think just needs to be added to nushell.
tertsdiepraam commentedon Aug 2, 2023
I've been thinking about this in the background and looked at nushell/nushell#9463. Here's what I think we should do:
Create a list of suitable utils for
nuNot all utils are suitable for
nu. For example, using the uutilslsover the nulswould probably be a bad idea. I like the start ofmvandcp. In general, I think the utils that are suitable are:For example:
b2sum(and similar),cp,dd,rmtest,ls,sort,true,falseThere is a grey area of utils which have some significant output, but are relatively simple, such as
wc. This could potentially be supported by creating somewordcountcrate extracted from uutils to be shared between the projects.Refactor those utils to expose their functionality
The nu cli interface is better than anything uutils could ever provide, so nu should do the argument parsing in my opinion. I think using
uumain(like in nushell/nushell#9463) is probably also more complicated than necessary and might introduce subtle bugs. I think we should instead provide an interface that exposes the internals of the util directly:This can then be used by nu.
Ensure that uutils does not exit or panic
uutils has largely been written to be run as a separate process and has used
std::process::exitquite freely in the past. We've been reducing this dramatically, but it's not yet fixed. There's also the occasional panic. Both of these would exit thenuprocess, which is of course unacceptable. The refactored utils should be checked to ensure that does not happen.Non-goal for now: streaming output
If we focus on utils that are not focused on output, we can ignore the issue of generating streamed structured output from uutils. I'd love to tackle this in the future, but it would be very complicated. So, I think it's easier to focus on the quite large collection of other utils first.
I'd love to hear what you think of this!
fdncred commentedon Aug 2, 2023
Thanks @tertsdiepraam. I appreciate your thoughtfulness. Here's some of my thoughts.
I generally agree with this approach, which is why I started with
cp. JT likes to say, "crawl, walk, run" which is basically what your proposal is. Start with the low hanging fruit and then look at the next lowest, and so on. So, yes, please. :) I'd love to move forward with this. I'm happy to just start withcpas a proof-of-concept. It seemed pretty straight forward.Another thing that I started playing around with was porting your tests into nushell. As far as I'm concerned, the more tests, the better, especially when bridging platforms like this. It was not trivial for the couple tests I moved over. I'd like to somehow just dump the tests your community has created for individual commands. We may have to think a little more on that front.
I do know that with the
mvcommand, there is some functionality that didn't work out-of-the-box, or said another way, nushell may have to change the way parameters are setup now formv. IIRC, it wasmv file file file dir. Nushell should support that, but the current code did not, so we'll have to investigate if this is a simple change or a more complex one.Exposing uutils
Optionsis a must. Agreed. If nushell is handling the command line parsing then we'll have the spans for "pretty" errors.Exit/Panic - Ya, that would be bad but it seems like it's a known issue that we can continue to work on.
ls- I'm very keen to use yourlsand stream the output somehow with a callback Fn or something. We have permission issues sometimes and those are just a pain to figure out because it's hard to reproduce them. I'm fine with waiting though. Another one that we have permission issues with iscd. I'm not sure I saw a uutilscdcommand though.I'll take a look through the commands and throw a list together of ones that I'd consider the "crawl" stage, the post it here, but like I said, let's just plan on
cpbeing first and let's just do one command. We just had a release, 0.83.1, so we have ~3 weeks until the next release 0.84.0. It would be cool to haveuu_cpinside of nushell by then. If we can't do it by then, that's no biggy though.tertsdiepraam commentedon Aug 2, 2023
Excellent! I love the "crawl, walk, run" saying!
Let's start with
cpthen. I think that it would be quite easy on the uutils side. We could just expose:coreutils/src/uu/cp/src/cp.rs
Line 214 in f37318d
and
coreutils/src/uu/cp/src/cp.rs
Line 1132 in f37318d
and the types used in
Options.(
SourceandTargetSliceare just aliases forPathBufandPathrespectively)I can add some additional documentation to those types and maybe clear up the naming a bit and then the rest would be up to you.
fdncred commentedon Aug 3, 2023
I took a swing at bucketing the commands into crawl, walk, run here https://docs.google.com/spreadsheets/d/1MP9V8BTtcy_3DIUT8025yTcGrjkIJ-ZKFT0uvJFw0Lo/edit#gid=0
I guessed at a bunch of them and some may be bucketed wrong, but it's a start.
tertsdiepraam commentedon Aug 11, 2023
I've made a PR to expose most of the necessary types of
cpfor use innu: #5152. Feedback is welcome!dmatos2012 commentedon Aug 12, 2023
Now, building up on my comment on the PR, I have some pain points specifically for us to solve here. @fdncred. You can check my WIP branch building on yours (very ugly code now), to see some of updates.
Particularly pain point for me was parsing as GNU wants. I agree with @tertsdiepraam that we should not behave exactly like GNU. Specific problems:
Some GNU flags have only a short flag, but no long flag, and with it their behavior changes, so makes it very difficult to implement. For instance, I made it so that
cp -u a bwould work by havingubeing aNamedArg. So in this case-uisNoneand it uses a default. But if you docp -u none a b,-uis none, but if you docp a b -uit wouldnt work since Nu would complain about"String is required for argument".And as far as I am concerned, I dont think
nuallows for no long flag, but only short flag, so we have to get around that as well.GNU is quite specific with how it uses flags. So short flag,
cp -u a bimplies an specific update,update=older, but if you use the long flag, you use it differentlycp --update=older a b(where=is required). Right now in my impl I have just parsed and made it work by doingcp --update older a bandcp -u older a b(without the=for simplicity). Therefore, I think we need to make a decision on how we are going to support the arguments, and what is allowed or not. Otherwise, it would become a headache to get the behavior exactly using the nushell parser.Finally there is the problem of setting some
Optionsthat are private inuutils, such asAttributethat would be quite cumbersome for us to implement, so we need to keep working with them to make this fully functional and painless for both.Once we define those, I think I could try to port more tests and improve the code, and add some docs.
Hopefully we can keep working together, to get close to a fully functional nushell using the
cpfromuutils:)tertsdiepraam commentedon Aug 12, 2023
Excellent observations! Thanks @dmatos2012!
Pedantic correction: in GNU,
-uand--updateare not separate but only the long version allows an optional argument. I think optional arguments in general might be a bit difficult to support in thenuparser.One workaround is to create flags like
--update-older,--update-all&--update-noneand then make-uthe short version of--update-older. Though that is a bit ugly I suppose.An example of a short argument that does not have a long counterpart at all is
-H. But there we could just come up with a long name for that.As for
Attributes, I think the solution there is to extract all of the parsing to a single function inuutilsand expose that to avoid duplication.For the first version, I think we should simplify as much as possible (e.g. no attributes or other complicated flags).
Edit: Maybe
SyntaxShapecould help for--update? Would something like this work?fdncred commentedon Aug 12, 2023
@dmatos2012 Great write up. Thanks for your effort! I like your "ugly" code, mine would've looked worse. 😆
I agree with your points and @tertsdiepraam has some interesting thoughts for work-arounds. One comment I'll throw in is no one said we have to support every parameter in
cp(or any other command). We can approachcpwith the crawl, walk, run strategy as well, if we want to. In my MVP comment in the code, I was only supporting a handful of parameters. Having said that, I would prefer to support all the parameters, but I'd like to leave our options open for now.As you brought up, we also need to determine how compatible we want to be with the GNU flags. I'm not sure myself. I want people to feel at home but nushell is already pretty different. I'm not convinced it's important that we be 100% compatible with GNU flags. I think if we have a way to do the same thing but with a different way, perhaps like
--update-older, then that's not a bad way to go. We'd probably just want to include something in the help to explain that.I'm going to try to get some other nushell core-team members to chime in here about these points. This is the "devil in the details" I was sure that we'd come across. There will be other problems with other commands like
mv, I'm sure.You can't tell but I'm bubbling over with excitement for this integration!
tertsdiepraam commentedon Aug 12, 2023
So am I!
tertsdiepraam commentedon Aug 19, 2023
Quick question just to be sure: what platforms should
nusupport? I see Linux, Mac and Windows in the nushell CI. Are there other platforms that are officially supported as well? If there's any required platforms that we don't test with uutils, we should add those to our CI.fdncred commentedon Aug 19, 2023
We're committed to MacOS, Linux, and Windows. However, we support people in other os's if we can. You can see that we have quite a few release assets to support people https://github.com/nushell/nushell/releases.
The only other thing I really see talked about on Discord is Android operating systems. I'm not familiar what those are but we allow people to put compile time
#[cfg()]points for android.11 remaining items
fdncred commentedon Oct 6, 2023
@tertsdiepraam when you have a sec, can you please provide an update on the
cpbugs that were being addressed for nushell? I looked and can't seem to find the PR where the fix was. My memory is failing right now but it was something about time/date stamps. Maybe it was with the --update?I just ask because we're getting closer to release time and we need that issue fixed before we release on 17 Oct. We'd like to have that landed well in advance of that, if it's not already landed, so that we can put in the uutils version of cp as the primary and have old-cp as a backup.
tertsdiepraam commentedon Oct 7, 2023
@fdncred Sure! As far as I know, there was this issue:
cp: copy to readonly file should fail on mac #5257There is a workaround for that issue in place, but there's some work to be done on making mac more robust in general:
cp: mac behaviour should mirror linux more closely #5349I don't recall any issues about datetime or
--updatethough?I tried these queries on both repos and nothing else seems to have popped up:
We have some work on compiling
cpwithoutclap: #5358 which is also for nushell.Here's some issues and PRs on other utils:
rm: expose main functionality for nushell #5294rm: make the utility public #5304mv: expose main functionality for nushell #5293whoamifunction (for nushell!) #5310mkdir: makemkdirpublic and document it #5329I'll make a GitHub project for these so we can track them.
Edit: The project is here: nushell integration
fdncred commentedon Oct 15, 2023
@tertsdiepraam @sylvestre Is it possible to get a coreutils release today/tomorrow maybe? We're getting close to the nushell release date of Oct-17 and need a release in order to ship the
uu_cpcrate as our officialcpcommand.If it's not possible, we'll need to roll back this PR nushell/nushell#10678 and wait for our next release 4 weeks later.
Just let me know please. Sorry to be a pain.
sylvestre commentedon Oct 15, 2023
let me try now :)
tertsdiepraam commentedon Oct 15, 2023
No need to be sorry! It makes perfect sense. We agreed to do the release before Oct 17, but I'm not sure when @sylvestre was planning to cut the release exactly.
sylvestre commentedon Oct 15, 2023
Still working on it but blocked on
the remote server responded with an error (status 429 Too Many Requests): You have published too many updates to existing crates in a short period of time. Please try again after Sun, 15 Oct 2023 15:30:45 GMT or email [email protected] to have your limit increased.sylvestre commentedon Oct 15, 2023
fixed https://crates.io/crates/coreutils
working on the release notes now
fdncred commentedon Oct 15, 2023
Thanks so much @sylvestre. ❤️ We really appreciate your support.
sylvestre commentedon Oct 15, 2023
Thanks
Here are the release notes:
https://github.com/uutils/coreutils/releases/tag/0.0.22
and I am mentioning your work ;)
dmatos2012 commentedon Oct 16, 2023
This is awesome! Sorry that I have been out of it for a bit, but where are we at now with the supported commands? I know the next commands were
mv,rm,whoamibut have they been merged, or there are still commands that can be taken? @fdncredfdncred commentedon Oct 16, 2023
@dmatos2012 none of them have been merged yet. I think we only have a PR for
whoamiatm. You can see issues here https://github.com/nushell/nushell/issues?q=is%3Aissue+is%3Aopen+coreutils+label%3Acoreutils-uutils. Feel free to make more issues with the commands you'd like to see. Also, feel free to start withmvorrm. I don't see anyone working on them yet. We're trying to keep up and use thecoreutils-utilslabel in PRs and Issues.fdncred commentedon Jan 16, 2024
For anyone watching this, I've added a list of commands that we'd like to integrate.
nushell/nushell#11549
roylaurie commentedon May 7, 2025
Thank you for the great work so far!
By coincidence, my first experience with the uutils packages was with
uu_touchrecently, which has had its API exposed. I was spoiled.I'd love to use something similar across commands each in suite (core, diff, find, etc.).
It wouldn't be remotely surprising to see uutils become a staple library ecosystem in Rust for system utilities, similar to how
tokiohas become a go-to for async utilities.