Make true return false less frequently#3014
Conversation
Now treats recognized command line options and ignores unrecognized command line options instead of returning a special exit status for them. There is one point of interest, which is related to an implementation detail in GNU `true`. It may return a non-true exit status (in particular EXIT_FAIL) if writing the diagnostics of a GNU specific option fails. For example `true --version > /dev/full` would fail and have exit status 1. This behavior was acknowledged in gnu in commit <9a6a486e6503520fd2581f2d3356b7149f1b225d>. No further justification provided for keeping this quirk. POSIX knows no such options, and requires an exit status of 0 in all cases. We replicate GNU here which is a consistency improvement over the prior implementation. Adds documentation to clarify the intended behavior more properly.
tertsdiepraam
left a comment
There was a problem hiding this comment.
First of all, that title is amazing 😄 And the docs look great too! I think this makes a lot of sense. I wanted to suggest using AppSettings::IgnoreErrors at first, but it turns out that suppresses the help and version messages too, so the solution you found is the best we can do for now.
Could you add some tests for this behaviour?
|
While adding more exhaustive tests, I noticed that |
|
With that change, would it make sense to do it the other way around? I.e. use |
This avoids hacking around the short options of these command line arguments that have been introduced by clap. Additionally, we test and correctly handle the combination of both version and help. The GNU binary will ignore both arguments in this case while clap would perform the first one. A test for this edge case was added.
|
Using dedicated options looks cleaner. At least the similarities, as well as differences, between |
|
Who thought Nice work! |
tertsdiepraam
left a comment
There was a problem hiding this comment.
Awesome! Only one nit about the formatting of the about
src/uu/false/src/false.rs
Outdated
| static ABOUT: &str = " | ||
| Returns false, an unsuccessful exit status. | ||
|
|
||
| Immediately returns with the exit status `1`. When invoked with one of the recognized options it | ||
| will try to write the help or version text. Any IO error during this operation is diagnosed, yet | ||
| the program will also return `1`. | ||
| "; |
There was a problem hiding this comment.
| static ABOUT: &str = " | |
| Returns false, an unsuccessful exit status. | |
| Immediately returns with the exit status `1`. When invoked with one of the recognized options it | |
| will try to write the help or version text. Any IO error during this operation is diagnosed, yet | |
| the program will also return `1`. | |
| "; | |
| static ABOUT: &str = "\ | |
| Returns false, an unsuccessful exit status. | |
| Immediately returns with the exit status `1`. When invoked with one of the recognized options it | |
| will try to write the help or version text. Any IO error during this operation is diagnosed, yet | |
| the program will also return `1`. | |
| "; |
src/uu/true/src/true.rs
Outdated
| static ABOUT: &str = " | ||
| Returns true, a successful exit status. | ||
|
|
||
| Immediately returns with the exit status `0`, except when invoked with one of the recognized | ||
| options. In those cases it will try to write the help or version text. Any IO error during this | ||
| operation causes the program to return `1` instead. | ||
| "; |
There was a problem hiding this comment.
| static ABOUT: &str = " | |
| Returns true, a successful exit status. | |
| Immediately returns with the exit status `0`, except when invoked with one of the recognized | |
| options. In those cases it will try to write the help or version text. Any IO error during this | |
| operation causes the program to return `1` instead. | |
| "; | |
| static ABOUT: &str = "\ | |
| Returns true, a successful exit status. | |
| Immediately returns with the exit status `0`, except when invoked with one of the recognized | |
| options. In those cases it will try to write the help or version text. Any IO error during this | |
| operation causes the program to return `1` instead. | |
| "; |
Good to know! Formatting was borrowed from |
Oh I see. That's a good idea! |
rivy
left a comment
There was a problem hiding this comment.
Looks good!
I like the revised logic.
👍🏻 for merge.
This acknowledges a quirk in GNU
trueand makestrueandfalsebehave consistent to it.Now treats recognized command line options and ignores unrecognized
command line options instead of returning a special exit status for
them.
truemay return a non-true exit status (in particular EXIT_FAIL)if writing the diagnostics of a GNU specific option fails. For example,
true --version > /dev/fullwould fail and have exit status 1. See commitsfor more details.
This now passes
tests/misc/false-status.sh.Closes: #3007, #2996, #2989