Conversation
| let s2 = "-h".to_string(); | ||
| let args = vec![OsString::from(s1), OsString::from(s2)]; | ||
| // Pass uucore::Args to app.uumain | ||
| uu_cp::uumain(&mut args.into_iter()); |
There was a problem hiding this comment.
how does uumain read in stdin? Can we redirect it?
There was a problem hiding this comment.
This is the first few lines from uumain
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args);So, it's reading the args passed in.
| // Create uucore::Args somehow from nushell args | ||
| let s1 = "cp".to_string(); | ||
| let s2 = "-h".to_string(); | ||
| let args = vec![OsString::from(s1), OsString::from(s2)]; |
There was a problem hiding this comment.
Makes me wonder if we instead want to create a From/Into for clap, so we can take the args and convert them using a converter that all the uu commands share.
There was a problem hiding this comment.
Seems reasonable. We need to construct our arguments so that they're compatible uucore::Args. I think this is the trait definition for that. https://github.com/uutils/coreutils/blob/17830ad6f84583a3d552b360dece0c74d7efc2e3/src/uucore/src/lib/lib.rs#L155-L167
| let args = vec![OsString::from(s1), OsString::from(s2)]; | ||
| // Pass uucore::Args to app.uumain | ||
| uu_cp::uumain(&mut args.into_iter()); | ||
| Ok(PipelineData::empty()) |
There was a problem hiding this comment.
Same question for output. Here we're dropping whatever they give us back, but how do we convert the uumain's stdout to something nushell can use? or, more importantly, can we convert it to structured data?
There was a problem hiding this comment.
My first thought was to start with commands like cp that don't really have structured output. The problem though is with error messages. We can catch parameter errors via our normal command argument parsing, but once we hand things off to blah::uumain() it does what it will do. This is the part we need to work with the uutils team on, having a way to hook the output.
You can see what uu_cp::uumain() is doing here https://github.com/uutils/coreutils/blob/17830ad6f84583a3d552b360dece0c74d7efc2e3/src/uu/cp/src/cp.rs#L651-L696
I think it's a good idea to somehow integrate with clap. It looks like 90% of what's going on in that cp.rs file I linked above is all clap/argument handling. So, we'd want to use that to our benefit somehow.
|
There's a current known problem with |
|
my two cents on this 😌
|
|
tbh, if i had not explicitely compiled Nushell with |
|
The changes to the cargo.toml files are two fold, (1) i tend to homogenize things, putting the nu- stuff together, adding new uu crates, and sorting crates and (2) the cargo/crates.io extension i use tends to reformat toml things. But reformatting the toml is the least thing I'm concerned about in this PR. |
|
In an attempt to have a tighter integration with uutils/coreutils I've created this issue in their repo uutils/coreutils#5088. |
| # uu_cp = { path = "../../../coreutils/src/uu/cp", version = "0.0.19" } | ||
| uu_mv = "0.0.19" | ||
| # uucore = { path = "../../../coreutils/src/uucore", version = "0.0.19", features = ["fsext"] } | ||
| uucore = { version = "0.0.19", features = ["fsext"] } |
There was a problem hiding this comment.
If fsext is necessary, that would be a bug in uutils. Does it still compile if you remove this?
There was a problem hiding this comment.
I'll test this and let you know. I didn't add it because it was required. I just copy-n-pasted from somewhere. It could've been from JT's exploration of adding df a few months back.
|
I've looked at this PR, but I posted my thoughts in the issue on uutils to avoid splitting the conversation: uutils/coreutils#5088 (comment) |
|
So, I checked out this branch, and tried to run the but I thought this isnt strictly necessary since we could just copy paste into nushell given its just bunch of diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs
index de9dd1c91..ac82f90f3 100644
--- a/src/uu/cp/src/cp.rs
+++ b/src/uu/cp/src/cp.rs
pub struct Options {
- attributes_only: bool,
+ pub attributes_only: bool,
// AND ALL THE OTHER FIELDS.OMMITED FOR BREVITY
}
@@ -765,7 +765,7 @@ impl Attributes {
}
}
- fn default() -> Self {
+ pub fn default() -> Self {
impl Options {
#[allow(clippy::cognitive_complexity)]
- fn from_matches(matches: &ArgMatches) -> CopyResult<Self> {
+ pub fn from_matches(matches: &ArgMatches) -> CopyResult<Self> {
-fn parse_path_args(mut paths: Vec<Source>, options: &Options) -> CopyResult<(Vec<Source>, Target)> {
+pub fn parse_path_args(
-fn copy(sources: &[Source], target: &TargetSlice, options: &Options) -> CopyResult<()> {
+pub fn copy(sources: &[Source], target: &TargetSlice, options: &Options) -> CopyResult<()> {
diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs
index 02724e1bf..593488276 100644
--- a/src/uucore/src/lib/lib.rs
+++ b/src/uucore/src/lib/lib.rs
-mod mods; // core cross-platform modules
+pub mod mods; // core cross-platform modules
I suppose the only big one would be the I guess this was more suitable on the |
|
@dmatos2012 My plan was a bit different: uutils/coreutils#5088 (comment) The reason is that the double argument parsing would be a bit error prone and redundant. Also, I think |
|
I apologize @tertsdiepraam if I misunderstood some of your comments, but basically what you mean is that what you would like is that everything is parsed from the impl Options {
#[allow(clippy::cognitive_complexity)]
- fn from_matches(matches: &ArgMatches) -> CopyResult<Self> {
+ pub fn from_matches(matches: &ArgMatches) -> CopyResult<Self> {
as we should handle the argument parsing in nu Thus, once we have parsed what is The mentioned {'else} branch mentioned that I checked out is the commented part, and does not use the |
|
Yes, that's indeed what I meant! |
|
Thanks @dmatos2012 for working on this. I'm interested to see how this will go. Hopefully |
|
closing in favor of #10097 |
) <!-- 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 Hi. Basically, this is a continuation of the work that @fdncred started. Given some nice discussions on #9463 , and [merged uutils PR](uutils/coreutils#5152) from @tertsdiepraam we have decided to give the `cp` command the `crawl` stage as it was named. > [!NOTE] Given that the `uutils` crate has not made the release for the merged PR, just make sure you checkout latest and put it in the required place to make this PR work. The aim of this PR is for is to see how to move forward using `uutils` crate. In order to getting this started, I have made the current `nushell cp tests` pass along with some extra ones I copied over from the `uutils` repo. With all of that being said, things that would be nice to decide, and keep working on: Crawl: - Handling of certain `named` flags, with their long and short forms(e.g. --update, --reflink, --preserve, etc), and using default values. Maybe `-u` can already have a `default_missing_value`. - Should we maybe just support one single option `switch` flags (see `--backup` in code) as a contrast to the other named args. - Complete test coverage from `uutils`. They had > 100 tests, and I could only port like 12 as they are a bit time consuming given they cannot be straight up copy pasted. Maybe we do not need all >100, but maybe the more relevant to what we want. - Refactor this code Walk: - Non fatal errors on `copy` from `utils`. Currently it just sends it to stdout but errors have no span - Better integration An added possibility is the addition of `SyntaxShape::OneOf()` for `Named` arguments which was briefly mentioned in the discord server, but that is still to be decided. This could greatly improve some of the integration. This would enable something like `cp --preserve [all timestamp]` or `cp --preserve all` to both work. I did not want to keep holding on this, and wait till I was happy with the code because I think its nice if everyone can start up and suggest refactors, but the main important part now was getting it out the door, as if I take my sweet time this will take way longer 😛 <!-- 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 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 - [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>
Description
This PR is a Proof of Concept MVP for replacing our
cpandmvcommands with theuutils/coreutilsversion. In this PR, we add a new feature callednuuuto expose these commands. If you compile withcargo b --features=nuuuthen thecpandmvyou get are the coreutils version. You can see they're different by looking at their help. If you compile without thenuuufeature, then you'll get the current nushell's version ofcpandmv.Some additional notes and thoughts here
Copy (ucp)
Move (umv)
User-Facing Changes
Tests + Formatting
After Submitting