Re: gnulib-tool.py argument parsing

2017-09-09 Thread Dmitry Selyutin
Hi Bruno,

to be honest, the command-line parsing in the gnulib-tool.py certainly
sucks.
I'm creating a new command-line parser from the scratch, and it works like
charm.
For example, it is much easier to avoid the error you described.
I'll take a look on how to fix the current parser and try to come up with
patch.
I guess there will be a lot of such errors until we switch to a new parser
though.

P.S. Frankly some of this errors are caused by the original solution.
I mean that some of the options (e.g. "modes", like --list, --import, etc.)
are not really options.
It was quite difficult to teach arparse to understand which options can be
combined and which not.

2017-09-09 0:44 GMT+03:00 Bruno Haible :

> Hi Dmitry,
>
> I'm banging my head against this:
>
>   $ ./gnulib-tool.py --test dirent
>   
>
>   $ ./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
>
>


-- 
With best regards,
Dmitry Selyutin


gnulib-tool.py argument parsing

2017-09-08 Thread Bruno Haible
Hi Dmitry,

I'm banging my head against this:

  $ ./gnulib-tool.py --test dirent
  

  $ ./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