refactor uu_ls so that crate users can call the ls without having to print everything to stdout
#9851
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was wanting to use
uu_lsin 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
LsOutputtrait.I created a
TextOutputstruct that impelments theLsOutputtrait so now thelist()function now looks like this:All of this allows crate callers like nushell to now do something like this:
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!!!