question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it possible to write 'xargs'

See original GitHub issue

I 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:closed
  • Created 11 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
keleshevcommented, Nov 18, 2012

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 into develop, 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?

0reactions
keleshevcommented, Jan 23, 2013

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 with any_options. Now, I think, docopt is much better with options_first.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linux and Unix xargs command tutorial with examples
The xargs command in UNIX is a command line utility for building an execution pipeline from standard input. Whilst tools like grep can...
Read more >
How to Use the Linux xargs Command - phoenixNAP
The xargs command builds and executes commands provided through the standard input. Learn how to use it with practical examples.
Read more >
How to Use the Bash xargs Commands - Linux Hint
The xargs is a bash command that allows the execution of multiple commands in the same line, whether the commands take parameters or...
Read more >
12 Practical Examples of Linux Xargs Command for Beginners
Xargs is a great command that reads streams of data from standard input, then generates and executes command lines; meaning it can take ......
Read more >
Make xargs execute the command once for each line of input
Its default behavior is to chunk the input into arguments and execute the command as few times as possible, passing multiple arguments to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found