public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug argparse/28317] New: Argp multiple parsers (child parsers) does not work as expected if any two parsers define options that have a common prefix
@ 2021-09-08  0:23 jivan.pal at gmail dot com
  2021-09-08  0:42 ` [Bug argparse/28317] " jivan.pal at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: jivan.pal at gmail dot com @ 2021-09-08  0:23 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28317

            Bug ID: 28317
           Summary: Argp multiple parsers (child parsers) does not work as
                    expected if any two parsers define options that have a
                    common prefix
           Product: glibc
           Version: 2.35
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: argparse
          Assignee: unassigned at sourceware dot org
          Reporter: jivan.pal at gmail dot com
  Target Milestone: ---

An Argp parser determines whether the user has passed a particular long option
by matching its *shortest unique prefix*, rather than the *whole string*. IMO,
this is undesirable behaviour in and of itself, but it also leads to a nasty
bug
when using child parsers: My command `drat` that I'm developing cannot have an
option called "block" in the main/parent parser whilst also having an argument
called "block-size" in a child parser, because each parser will match the
shortest prefix (i.e. `--b`, `--bl`, `--blo` etc. all suffice for each parser)
and the child parser gets priority, meaning that when I do

`drat read --container /dev/disk0s2 --block 0x123`,

it performs the equivalent of

`drat read --container /dev/disk0s2 --block-size 0x123`,

which is of course not what I want...

This bug is present because Argp relies on the behaviour of `getopt_long()`,
which is defined as follows (from documentation of `_getopt_internal_r()`,
emphasis mine):

> Long-named options begin with '--' instead of '-'. ***Their names may be
> abbreviated as long as the abbreviation is unique or is an exact match for
> some defined option.***  If they have an argument, it follows the option name
> in the same ARGV-element, separated from the option name by a '=', or else the
> in next ARGV-element. When 'getopt' finds a long-named option, it returns 0 if
> that option's 'flag' field is nonzero, the value of the option's 'val' field
> if the 'flag' field is zero.

The emphasised behaviour is implemented in `process_long_option()`, in the
first
`if (pfound == NULL)` block, which can be found in glibc git commit `2738480a`
(latest commit on `master` at time of writing), file `posix/getopt.c`, lines
221-307.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug argparse/28317] Argp multiple parsers (child parsers) does not work as expected if any two parsers define options that have a common prefix
  2021-09-08  0:23 [Bug argparse/28317] New: Argp multiple parsers (child parsers) does not work as expected if any two parsers define options that have a common prefix jivan.pal at gmail dot com
@ 2021-09-08  0:42 ` jivan.pal at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: jivan.pal at gmail dot com @ 2021-09-08  0:42 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28317

Jivan Pal <jivan.pal at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #1 from Jivan Pal <jivan.pal at gmail dot com> ---
Turns out there was a bug in my code, and Argp handles this situation properly
to avoid such conflicts.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-08  0:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  0:23 [Bug argparse/28317] New: Argp multiple parsers (child parsers) does not work as expected if any two parsers define options that have a common prefix jivan.pal at gmail dot com
2021-09-08  0:42 ` [Bug argparse/28317] " jivan.pal at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).