Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uname: Refactor into public fns for Nushell #5921

Merged
merged 8 commits into from
Feb 16, 2024

Conversation

dmatos2012
Copy link
Contributor

Hi,
As part of the initial step for using uname in nushell, I factored the util to have the sort of same structure as umv or ucp, and thus made the respective Options and uname fn public. Thank you for your time.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/rm/rm1 (fails in this run but passes in the 'main' branch)

@sylvestre
Copy link
Sponsor Contributor

not really about this PR but it made me think about testing. How can we make sure we don't regress these changes for you folks ?

@dmatos2012
Copy link
Contributor Author

dmatos2012 commented Jan 31, 2024

not really about this PR but it made me think about testing. How can we make sure we don't regress these changes for you folks ?

I am still making a small change, so not ready still the PR. But, what do you think about this @fdncred

@fdncred
Copy link

fdncred commented Jan 31, 2024

@sylvestre @dmatos2012 We hope to have tests in nushell that I guess will do the uname calls in the CI, no clue what that will look like or if it'll even work. Agreed that we don't want to regress but inevitably people will find issues that we might trace back to a uu_ crate, just like they do with other crates now. The good news is y'all are friendly and responsive. I can't say that for some of our crates we depend on.

I think the best we can do is have our "normal" testing in this repo and once we integrate have the nushell level of testing in that repo. @dmatos2012 has done a great job getting good tests setup in the nushell repo, so I hope to continue that strategy. I'm not sure what else we can do. I wouldn't think you'd want to run nushell tests in this repo, but that's the only other thing I can think of.

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small initial comments. It's looking pretty good!

Comment on lines 18 to 26
pub mod options {
pub static ALL: &str = "all";
pub static KERNEL_NAME: &str = "kernel-name";
pub static NODENAME: &str = "nodename";
pub static KERNEL_VERSION: &str = "kernel-version";
pub static KERNEL_RELEASE: &str = "kernel-release";
pub static MACHINE: &str = "machine";
pub static PROCESSOR: &str = "processor";
pub static HARDWARE_PLATFORM: &str = "hardware-platform";
pub static OS: &str = "operating-system";
static ALL: &str = "all";
static KERNEL_NAME: &str = "kernel-name";
static NODENAME: &str = "nodename";
static KERNEL_VERSION: &str = "kernel-version";
static KERNEL_RELEASE: &str = "kernel-release";
static MACHINE: &str = "machine";
static PROCESSOR: &str = "processor";
static HARDWARE_PLATFORM: &str = "hardware-platform";
static OS: &str = "operating-system";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this for consistency with the other utilities. It's also a change that is not really relevant to nushell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is still there, what I changed was mod Options {} to the same consistent way I saw in mv and cp with pub struct Options {} unless you meant something else.?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did removed the options module around the arguments right? That's what I meant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok sorry, the + liens in the diff tripped me up, bad brain fart , but added it back again

Comment on lines 53 to 58
.for_each(|name| {
if let Some(name) = name {
output.push_str(name);
output.push(' ');
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could be done with .flatten. So something like:

for name in [...].into_iter().flatten() {
    output.push_str(name);
    output.push(' ');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL; didnt know you could flatten an option. Pretty cool, thx!

Comment on lines 74 to 78
let kernel_name = if opts.kernel_name || opts.all || none {
Some(uname.sysname().to_string_lossy().to_string())
} else {
None
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all essentially .then:

let kernel_name  = (opts.kernel_name || opts.all || none).then(|| {
    uname.sysname().to_string_lossy().to_string()
});

@tertsdiepraam
Copy link
Member

I think on the testing side, we should have integration tests for the parts of the API that nushell uses. At least then we'll get a warning from our own CI if we break the API. I also just listened to a talk about cargo-semver-checks maybe we could use that too 😄

@dmatos2012
Copy link
Contributor Author

Thanks for the feedback @tertsdiepraam ,I think I addressed them all :)

@dmatos2012
Copy link
Contributor Author

friendly ping @tertsdiepraam @sylvestre :)

@cakebaker cakebaker merged commit de74f70 into uutils:main Feb 16, 2024
58 of 62 checks passed
@cakebaker
Copy link
Contributor

Thanks!

ysthakur pushed a commit to ysthakur/coreutils that referenced this pull request Feb 27, 2024
* Refactor to use options struct and make it public for Nushell

* Return the output for use in nushell

* wip:opt1

* Add UNameOutput struct instead

* Apply req changes

* change back to mod options

* uname: add empty line & fix position of comment

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
fdncred added a commit to nushell/nushell that referenced this pull request Mar 25, 2024
Hi,
This PR aims at implementing the first iteration for `uname` using
`uutils`. Couple of things:
* Currently my [PR](uutils/coreutils#5921) to
make the required changes is pending in `uutils` repo.
* I guess the number of flags has to be investigated. Still the tests
cover all of them.


<!--
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.
-->

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

# Tests + Formatting
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- [X] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [X] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used`
to check that you're using the standard code style
- [X] `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))
- [X] `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 <343840+fdncred@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants