bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib-tool.py argument parsing


From: Bruno Haible
Subject: gnulib-tool.py argument parsing
Date: Fri, 08 Sep 2017 23:44:41 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-93-generic; KDE/5.18.0; x86_64; ; )

Hi Dmitry,

I'm banging my head against this:

  $ ./gnulib-tool.py --test dirent
  <works, creates a temporary directory>

  $ ./gnulib-tool.py --test --destdir=../testdir-dirent dirent
  usage: gnulib-tool.py --help
  ./gnulib-tool.py: error: unrecognized arguments: dirent

The argument parsing conventions for POSIX/GNU programs distinguish
  * option with 0 or 1 arguments,
  * non-option arguments.
In strict POSIX and in gnulib-tool, the non-option arguments come last,
that is, the user is not allowed to write

$ ./gnulib-tool.py dirent --test --destdir=../testdir-dirent
or
$ ./gnulib-tool.py --test dirent --destdir=../testdir-dirent

I'm fine with argument reordering, that is, to *allow* different ways
of specifying the arguments. But gnulib-tool.py is currently *forcing*
a specific argument order which is
  1. invalid for gnulib-tool
  2. not according to strict POSIX.
Namely, it *forces* the syntax
$ ./gnulib-tool.py --test dirent --destdir=../testdir-dirent
or
$ ./gnulib-tool.py --destdir=../testdir-dirent --test dirent


This "unrecognized arguments" error is explained in
https://stackoverflow.com/questions/12818146/

So, I think the fix will be to

1) replace the line
    cmdargs = parser.parse_args()
with
    cmdargs, nonoption_args = parser.parse_known_args()

2) Revisit all uses of nargs='+' and nargs='*'.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]