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

ls: when -aA are provided, the order matters #3285

Merged
merged 3 commits into from
Mar 21, 2022

Conversation

sylvestre
Copy link
Contributor

No description provided.

@tertsdiepraam
Copy link
Member

Ohh good find! Instead of manually checking the indices, we should probably make them override each other with clap's Arg::overrides_with, so we don't need to implement the logic ourselves.

@sylvestre
Copy link
Contributor Author

it supports the order?
-aA is different than -Aa

@tertsdiepraam
Copy link
Member

Yeah the overrides_with method makes it so that the earlier argument is automatically discarded when the second one is passed, so -aA is equivalent to -A and -Aa is equivalent to -a.

@sylvestre
Copy link
Contributor Author

bien vu, done :)

@anastygnome
Copy link
Contributor

anastygnome commented Mar 21, 2022

Hey there

Yeah the overrides_with method makes it so that the earlier argument is automatically discarded when the second one is passed, so -aA is equivalent to -A and -Aa is equivalent to -a.

Nice finding @tertsdiepraam !

@sylvestre You should consider adding a comment there, as I, unfamiliar with this code , had to read this PR to understand this part of the code, and this is just using some external lib logic.

This could also be reused in other tools.

anything that's clever, or that you find surprising should be commented.

(a CS prof. of mine, back in the day)

@sylvestre
Copy link
Contributor Author

Yeah:
Changes from main: PASS +1 / FAIL -1 / ERROR +0 / SKIP +0

@sylvestre
Copy link
Contributor Author

@anastygnome I think it is self explanatory but as it doesn't hurt, I added comments :)

@sylvestre sylvestre requested a review from tertsdiepraam March 21, 2022 09:21
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.

Looks good, but while we're changing this, both should also override themselves (so that ls -aa is possible). @anastygnome this is a technique used throughout the codebase, but you're right that more comments never hurt anybody :)

@sylvestre
Copy link
Contributor Author

both should also override themselves

I used .multiple_occurrences for this

@sylvestre sylvestre requested a review from tertsdiepraam March 21, 2022 14:32
@tertsdiepraam
Copy link
Member

Sure! That's a good solution in this case. More generally, we should probably push for using https://docs.rs/clap/3.1.6/clap/struct.App.html#method.args_override_self in (almost) all utils.

@tertsdiepraam tertsdiepraam merged commit 5eeac58 into uutils:main Mar 21, 2022
@sylvestre sylvestre deleted the ls_aA branch March 21, 2022 17:17
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.

3 participants