Fix: coreutils now allows options with incomplete names#11348
Fix: coreutils now allows options with incomplete names#11348GunterSchmidt wants to merge 6 commits intouutils:mainfrom
Conversation
Addresses issue uutils#10269. * Allow options with --l, --li or similar for --list * Prioritize options: -V --list --help will return help -V --list will return version * Added tests * Selected option now is returned as Enum for better code readability. * No functional changes * first arg needs to be the binary/executable. \ This is usually coreutils, but can be the util name itself, e.g. 'ls'. \ The util name will be checked against the list of enabled utils, where * the name exactly matches the name of an applet/util or * the name matches <PREFIX><UTIL_NAME> pattern, e.g. 'my_own_directory_service_ls' as long as the last letters match the utility. * coreutils arg: --list, --version, -V, --help, -h (or shortened long versions): \ Output information about coreutils itself. \ Multiple of these arguments, output limited to one, with help > version > list. * util name and any number of arguments: \ Will get passed on to the selected utility. \ Error if util name is not recognized. * --help or -h and a following util name: \ Output help for that specific utility. \ So 'coreutils sum --help' is the same as 'coreutils --help sum'.
|
GNU does not have |
| let util_name = if let Some(&util) = matched_util { | ||
| Some(OsString::from(util)) | ||
| } else if is_coreutils || binary_as_util.ends_with("box") { | ||
| // todo: Remove support of "*box" from binary |
There was a problem hiding this comment.
This is not too easy. We have this for BusyBox tests.
There was a problem hiding this comment.
Ah, interesting. I just saw the to do and removed it. Will implement it again.
-V is not GNU, but uutils standard, see extensions.md.
There was a problem hiding this comment.
Actually, I'm considering to remove -h,-V extensions to avoid confliction in the future. (We already have some probrematic conflictions...)
|
GNU testsuite comparison: |
This comment was marked as outdated.
This comment was marked as outdated.
|
Would you wait merging #10889 ? I'm worrying about regression. |
Fixed some clippy warnings.
|
Sure, I do not mind merging #10889 first at all. This is a core module, so safety first. I am using Enums as this makes the prioritization logic a bit simpler and increases readability. In my experience, Enums make code more maintainable, but that may be a personal preference. Diff is large, indeed. This is because I moved most error situations to the top and all code regarding coreutil options to the bottom so it is not scattered around. I also removed some nesting levels, making it easier to follow the code structure. |
|
able to split PR? overkill? |
|
GNU testsuite comparison: |
The previous commit had some additional code restructuring which made diff checking difficult. Here the same functionality is implemented, but now it is clearer that only the None path of "match utils.get" has changed. This only affects coreutils own option parsing.
|
I see your point. This version now has less changes to the original. Only the None-case has changed when no util was found to redirect to. |
|
I stil think enum is overkill... |
|
Well, I have to disagree with that, as Enums work faster and are more secure, but that is opinionated. I am flexible on this, so I removed the Enum. |
|
It might better to just switch to clap which supports incomplete flags and localization (though I don't like clap's overhead...)
|
|
Why, you would be adding a lot of overhead for a selection of 3 options. The first commit I did was the cleanest, safest and most readable code. |
Enums are technically superior: Easier to maintain, safer to work with and more performant.
|
I'm not hoping to reinvent the wheel. I might try to use clap at cold code-path of |
|
GNU testsuite comparison: |
|
And you think that implementing clap is less complex? That is like using a Content Management System to write a single note. |
|
Ofcause. We are already relying on clap's incomplete long arg support at most utils. |
How about |
|
GNU's |
|
About your question: "How about coreutils sort -h where -h is "not" help?" This is how it works:
I do not know why this was build into coreutils, but I did not want to change it. |
|
OK. I'll drop coreutils --help string in any cases. |
Addresses issue #10269.
Changes
coreutils arguments