[PATCH] libbb: make '--help' handling more consistent
Denys Vlasenko
vda.linux at googlemail.com
Tue Aug 30 15:13:17 UTC 2022
Fixed in git
On Thu, Aug 25, 2022 at 7:26 AM Harald van Dijk <harald at gigawatt.nl> wrote:
>
> This breaks the [ command. Previously, [ --help would show help, which
> is okay as an extension since it is not valid with the standard [
> command. This change makes [ --help ] also show help, when it is
> required to just check that the string --help is not empty.
>
> On 22/08/2022 13:07, Denys Vlasenko wrote:
> > Applied, thank you
> >
> > On Sun, May 1, 2022 at 10:46 AM Ron Yorston <rmy at pobox.com> wrote:
> >>
> >> Running an applet with '--help' as its only argument is treated
> >> as a special case. If additional arguments follow '--help' the
> >> behaviour is inconsistent:
> >>
> >> - applets which call single_argv() print help and do nothing else;
> >>
> >> - applets which call getopt() report "unrecognized option '--help'"
> >> and print help anyway;
> >>
> >> - expr says "expr: syntax error" and doesn't print help;
> >>
> >> - printenv silently ignores '--help', prints any other variables
> >> and doesn't print help;
> >>
> >> - realpath says "--help: No such file or directory", prints the path
> >> of any other files and doesn't print help.
> >>
> >> If the first argument is '--help' ignore any other arguments and print
> >> help. This is more consistent and most likely what the user wanted.
> >>
> >> See also commit 6bdfbc4cb (libbb: fix '--help' handling in
> >> FEATURE_SH_NOFORK=y).
> >>
> >> function old new delta
> >> show_usage_if_dash_dash_help 75 69 -6
> >> ------------------------------------------------------------------------------
> >> (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-6) Total: -6 bytes
> >>
> >> Signed-off-by: Ron Yorston <rmy at pobox.com>
> >> ---
> >> libbb/appletlib.c | 5 ++---
> >> 1 file changed, 2 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/libbb/appletlib.c b/libbb/appletlib.c
> >> index 841b3b873..d56b5b409 100644
> >> --- a/libbb/appletlib.c
> >> +++ b/libbb/appletlib.c
> >> @@ -258,7 +258,6 @@ void lbb_prepare(const char *applet
> >> /* Redundant for busybox (run_applet_and_exit covers that case)
> >> * but needed for "individual applet" mode */
> >> if (argv[1]
> >> - && !argv[2]
> >> && strcmp(argv[1], "--help") == 0
> >> && !is_prefixed_with(applet, "busybox")
> >> ) {
> >> @@ -940,8 +939,8 @@ void FAST_FUNC show_usage_if_dash_dash_help(int applet_no, char **argv)
> >> && applet_no != APPLET_NO_echo
> >> # endif
> >> ) {
> >> - if (argv[1] && !argv[2] && strcmp(argv[1], "--help") == 0) {
> >> - /* Make "foo --help" exit with 0: */
> >> + if (argv[1] && strcmp(argv[1], "--help") == 0) {
> >> + /* Make "foo --help [...]" exit with 0: */
> >> xfunc_error_retval = 0;
> >> bb_show_usage();
> >> }
> >> --
> >> 2.35.1
> >>
> >> _______________________________________________
> >> busybox mailing list
> >> busybox at busybox.net
> >> http://lists.busybox.net/mailman/listinfo/busybox
> > _______________________________________________
> > busybox mailing list
> > busybox at busybox.net
> > http://lists.busybox.net/mailman/listinfo/busybox
> >
More information about the busybox
mailing list