Make it possible to write 'xargs'
See original GitHub issueI have this test of options parsers, and almost every one fails, including docopt: Can I write ‘xargs’?
Here’s a simplified usage string:
"""Usage:
xargs.py [options] [COMMAND [ARG...]]
Options:
--null,-0 Input items terminated by 0
"""
The problem is that Docopt allows interspersed options, per the GNU(?) convention. (This is a good default! I don’t dispute that.) This means that the command line xargs.py foo -0
produces this option dictionary:
{'--null': True,
'ARG': [],
'COMMAND': 'foo'}
instead of this one:
{'--null': False,
'ARG': ['-0'],
'COMMAND': 'foo'}
Obviously I could require that the user enter --
in there, but that is both obnoxious and not the typical situation for a program which runs another command passed on the command line. (E.g. time
, valgrind
, env
, etc.)
(Incidentally, --
handling IMO doesn’t seem very good either: If I run xargs.py -- foo
what I get is
{'--null': False,
'ARG': ['foo'],
'COMMAND': '--'}
while standard convention is that the – is basically transparent to the program’s meaning and thus it seems like it should be transparent to the program’s code, so forcing the programmer to manually shift the positional arguments down (or explicitly list a variant of the command with --
) seems wrong.)
Issue Analytics
- State:
- Created 11 years ago
- Comments:21 (10 by maintainers)
Top GitHub Comments
I think I changed my mind and started appreciating
disable_interspersed_args
, so If someone does a pull-request into a new branch (is it possible in git?) or intodevelop
, I will include it in the next version.However, I don’t like the name, we need to come up with something else. Maybe
posixly_correct
similar to getopt? Or maybe something else?0.6.0 is now released with
options_first
argument as discussed above. Thanks a lot guys and especially @EvanED for suggestion and discussion. I could have made a big mistake withany_options
. Now, I think, docopt is much better withoptions_first
.