Skip to content

Only sometimes, a late --help should override other errors #130

@BenWiederhake

Description

@BenWiederhake

According to the GNU implementation, arguments should be parsed left-to-right, early errors take precedence, and a later --help is IGNORED:

$ LC_ALL=C du -B kb --help README.* # early error overrides --help
du: invalid suffix in -B argument 'kb'
[$? = 1]

At the same time, with the same command, the OPPOSITE is true:

$ LC_ALL=C du --invalid README.* # --invalid is an error, does NOT print manpage
du: unrecognized option '--invalid'
Try 'du --help' for more information.
[$? = 1]
$ LC_ALL=C du --invalid --help README.* # late --help still counts, for some reason
du: unrecognized option '--invalid'
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize device usage of the set of FILEs, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with NUL, not newline
<SNIP manpage>
$ echo $? # Not an error!
0

So apparently we should first parse arguments, and raise on errors within recognized options, only then check if --help exists, and only then raise on unrecognized options.

Insanity!

I'm not sure how to do this best, and I'm afraid this is incompatible with #113.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions