Skip to content

Conversation

@fdncred
Copy link

@fdncred fdncred commented Dec 26, 2025

I was wanting to use uu_ls in nushell and found out that I couldn't because some of the internals weren't exposed in a way such that crate callers could really use it. So, I was wondering if something like this PR would be something worth considering?

It refactors the code in such a way so that crate callers could call uu_ls and get structured data back instead of everything printing to stdout. It does this without a breaking change by implementing a type of visitor pattern through the LsOutput trait.

I created a TextOutput struct that impelments the LsOutput trait so now the list() function now looks like this:

   pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
       let mut output = TextOutput::new(config);
       list_with_output(locs, config, &mut output)
   }

All of this allows crate callers like nushell to now do something like this:

use uu_ls::{Config, list_with_output, CollectorOutput};
use std::path::Path;

let mut output = CollectorOutput::new();
list_with_output(vec![Path::new(".")], &config, &mut output)?;

for entry in output.entries() {
    // Convert to Nushell Value with full type information
    let name = entry.display_name.to_string_lossy();
    let size = entry.size().unwrap_or(0);
    let is_dir = entry.is_dir();
    // ...
}

One last note, I know I didn't discuss this with anyone so it won't hurt my feelings if this PR isn't accepted. I'm open to whatever. I was just trying to figure out a way to reuse more of the excellent coreutils code. Thanks for such a great repo!!!

@github-actions
Copy link

GNU testsuite comparison:

Note: The gnu test tests/pr/pr-tests was skipped on 'main' but is now failing.

@sylvestre
Copy link
Contributor

sorry, it needs to be rebased

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.

2 participants