Skip to content

implement whoami using uutils - #10488

Merged
fdncred merged 9 commits into
nushell:mainfrom
tertsdiepraam:uwhoami
Oct 25, 2023
Merged

fdncred merged 9 commits into
nushell:mainfrom
tertsdiepraam:uwhoami

Conversation

@tertsdiepraam

@tertsdiepraam tertsdiepraam commented Sep 24, 2023 •

Copy link
Copy Markdown
Contributor

Description

Implements whoami using the whoami command from uutils as backend. This is a draft because it depends on uutils/coreutils#5310 and a new release of uutils needs to be made (and the paths in Cargo.toml should be updated). At this point, this is more of a proof of concept 😄

Additionally, this implements a (simple and naive) conversion from the uutils UResult to the nushell ShellError, which should help with the integration of other utils, too. I can split that off into a separate PR if desired.

I put this command in the "platform" category. If it should go somewhere else, let me know!

The tests will currently fail, because I've used a local path to uutils. Once the PR on the uutils side is merged, I'll update it to a git path so that it can be tested and runs on more machines than just mine.

User-Facing Changes

New whoami command. This might break some users who expect the system whoami command. However, the result of this new command should be very close, just with a nicer help message, at least for Linux users. The default whoami on Windows is quite different from this implementation: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/whoami

Tests + Formatting

After Submitting

@fdncred fdncred added the A:coreutils-uutils Changes relating to coreutils/uutils label Sep 24, 2023
@fdncred

fdncred commented Sep 24, 2023

Copy link
Copy Markdown
Contributor

Thanks @tertsdiepraam. Looks like you were right when you said that whoami would be easy. 😆

@tertsdiepraam

tertsdiepraam commented Sep 24, 2023 •

Copy link
Copy Markdown
Contributor Author

Indeed! It's a very simple command without any flags. And it's a good excuse to implement conversion for errors as well. If you approve the CI now, the tests should work, because the PR has been merged on our side!

@fdncred

fdncred commented Sep 24, 2023

Copy link
Copy Markdown
Contributor

i restarted the ci but there are more ci errors. something else must be going on.

@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

@fdncred Ah yeah, some dependency conflicts. Should be fixed now (at least works for me now with cargo run --locked)!

@fdncred

fdncred commented Sep 24, 2023

Copy link
Copy Markdown
Contributor

@tertsdiepraam looks like you need .allow_variants_without_examples(true) in the signature.

@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

I figured my example covered that, but I suppose that's nothing -> nothing because I didn't (and can't) specify the output?

@fdncred

fdncred commented Sep 24, 2023

Copy link
Copy Markdown
Contributor

I figured my example covered that, but I suppose that's nothing -> nothing because I didn't (and can't) specify the output?

ya, nothing -> nothing may be a bug on our side?

@fdncred

fdncred commented Sep 24, 2023

Copy link
Copy Markdown
Contributor

Ah, the latest CI failure is because we don't allow substrings of the command name to be in the search terms, so who is a substring of whoami. I forgot we added that. LOL.

@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

Haha alright, I'll fix that up, too.

@tertsdiepraam
tertsdiepraam marked this pull request as ready for review October 15, 2023 18:39
@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

If I'm not mistaken, this is unblocked by the latest uutils release. I'm on holiday, so I can't fix the Cargo.lock issue and update the dependencies. @fdncred if you want this in the upcoming release feel free to update this PR. If not, I'll update it myself in about a week. 🙂

@kubouch

kubouch commented Oct 16, 2023

Copy link
Copy Markdown
Contributor

I have just one comment about the error conversion. In Nushell, errors with spans should be used unless absolutely necessary. The ShellError::IOError conversion is more of a technical debt on our side that we should remove or add a span to it. Otherwise cool, I have no complaints.

@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

Alright, so the span here would just be whoami then? The automatic conversion from UError might need to change a bit then. Again, I can't fix it right now, but feel free to edit. I can also make a new PR with the error change in a week if you still want to merge this in its current state. All up to you!

@fdncred

fdncred commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor

I made some quick changes to this to add a span to the error message. I removed the way the previous error message was created. At some point, we need to add a good way to map between UError and ShellError and pass spans in order to print our normal nushell errors.

I also added coreutils as a search term. I thought it would be good to have that everywhere we integrate as an easy way of finding all the integrated commands, although cp doesn't currently have that but we can fix that.

@tertsdiepraam

tertsdiepraam commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor Author

Excellent! Exactly what I had in mind! I'll think about easier conversion of the error types for the other utils. I can't approve this PR, because it's my own, but consider it approved 😄

@fdncred

fdncred commented Oct 16, 2023

Copy link
Copy Markdown
Contributor

Thanks @tertsdiepraam. Any help you can provide with better error handling between coreutils and nushell would be appreciated. We'll probably wait on landing this until after the release. We're very cautious about landing PR without a couple days of a release. We've been burned on that in the past.

@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

I understand completely! We'll test this properly after the release 👍

@kubouch

kubouch commented Oct 16, 2023

Copy link
Copy Markdown
Contributor

Instead of implementing the From trait, the converter could look something like ShellError::from_uerror(error: UError, span: Span) -> ShellError and inside you'd create a spanned error.

@tertsdiepraam

tertsdiepraam commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor Author

Yeah it could be something along those lines! Definitely sounds like a good idea for the simple cases like this one. Sometimes we might also want some more control. It might be nice for instance if there was some way for uutils to indicate which argument caused the error. Even better, we might be able to rework the uutils errors some more to make those pretty too! I'm a bit jealous of those pretty miette errors 😄 That would be using the same information then.

@amtoine

amtoine commented Oct 25, 2023

Copy link
Copy Markdown
Member

not sure i remember if there was some other blocker for this PR? 🤔

if not, @tertsdiepraam, could you fix the Cargo.toml? 😇

@fdncred
fdncred merged commit e2fb0e5 into nushell:main Oct 25, 2023
@fdncred

fdncred commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

Thanks @tertsdiepraam! I forgot about this one, LOL.

@fdncred fdncred added notes:mention Noted in "Hall of Fame" section and removed status:wait-until-after-nushell-release labels Oct 25, 2023
@fdncred

fdncred commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

I think we definitely still need to work on the UError to ShellError thing though.

@tertsdiepraam

Copy link
Copy Markdown
Contributor Author

I was working on fixing these conflicts at the same time and so confused when everything was suddenly fixed 😄 Thanks for the fixes!

@fdncred

fdncred commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

lolz, sorry for fixing them from underneath you.

hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->

Implements `whoami` using the `whoami` command from uutils as backend.
This is a draft because it depends on
uutils/coreutils#5310 and a new release of
uutils needs to be made (and the paths in `Cargo.toml` should be
updated). At this point, this is more of a proof of concept 😄

Additionally, this implements a (simple and naive) conversion from the
uutils `UResult` to the nushell `ShellError`, which should help with the
integration of other utils, too. I can split that off into a separate PR
if desired.

I put this command in the "platform" category. If it should go somewhere
else, let me know!

The tests will currently fail, because I've used a local path to uutils.
Once the PR on the uutils side is merged, I'll update it to a git path
so that it can be tested and runs on more machines than just mine.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

New `whoami` command. This might break some users who expect the system
`whoami` command. However, the result of this new command should be very
close, just with a nicer help message, at least for Linux users. The
default `whoami` on Windows is quite different from this implementation:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/whoami

# Tests + Formatting
<!--
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 -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->

---------

Co-authored-by: Darren Schroeder <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:coreutils-uutils Changes relating to coreutils/uutils notes:mention Noted in "Hall of Fame" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants