Questions tagged [docopt]

Framework for creating command-line interfaces from docstrings.

docopt creates beautiful command-line interfaces:

The docopt Python module allows you to create powerful command line interfaces by simply passing a usage string like those printed by many posix tools. The command parser is automatically generated from the usage and the results of parsing provided arguments are returned as a dict.

Video introduction to docopt: PyCon UK 2012: Create beautiful command-line interfaces with Python.

The docopt module has also been ported to several other programming languages

145 questions
22
votes
3 answers

Python - Difference between docopt and argparse

I have to write a command-line interface and I've seen I can use docopt and argparse. I would like to know what are the main differences between the two so that I can make an enlightened choice. Please stick to the facts. I don't want Wow. docopt.…
baldurmen
  • 589
  • 2
  • 6
  • 14
21
votes
1 answer

Why doesn't my docopt option have its default value?

I'm using docopt in an example for a module I'm working on, and all the option default values are working except one. I've modified all the code containing and surrounding the option trying to identify the problem, but it won't take a default…
kitsu.eb
  • 2,578
  • 24
  • 27
9
votes
2 answers

How to specify one optional argument several times in docopt

I'd like to design my command line application in a way that one option, let's call it comment, can be specified several times, e.g., $ ./my_app.py --comment="Comment 1" --comment="Comment 2" Can this be done with docopt? I checked the docopt…
andreas-h
  • 9,199
  • 17
  • 52
  • 69
8
votes
1 answer

including more than one list of arguments with docopt

I'm using for my python application as a command line tool, the feature docopt library. It's easy to implement the commands with that library. But, for now I couldn't find out the way to accomplish the following requirement: the docstring…
jonaprieto
  • 1,773
  • 1
  • 15
  • 15
7
votes
2 answers

How to prevent command line args from being interpreted by R vs. only by my script?

I'm using the docopt implementation for R. My script has a command line option where the short form is -g. When I run my script, it seems this argument is first interpreted by R and then by my script. Therefore I get a wrist slap about not…
jennybryan
  • 2,378
  • 13
  • 29
7
votes
1 answer

Docopt: options after repeating elements are interpeted as repeating elements

I am using docopt in my simple Python program: #!/usr/bin/env python """ Farmers market Usage: farmersmarket.py buy -i -q [] [-p ] [-dvh] farmersmarket.py -d | --debug farmersmarket.py -v | --version …
mat
  • 117
  • 1
  • 5
5
votes
1 answer

docopt + schema validation

Is there a better way of handling this validation: #!/usr/bin/env python """ command. Usage: command start ID command finish ID FILE command (-h | --help) command (-v | --version) Arguments: FILE input file PATH out…
prafulfillment
  • 861
  • 2
  • 8
  • 26
5
votes
4 answers

Why are defaults not appearing in my command-line argument dictionary from docopt?

I've been trying to use docopt to make a simple CLI, but for some reason my default parameters are not appearing. Below is my test code. I am using the latest version of docopt.py from the github repository. """ Usage: scrappy ...…
Louis Thibault
  • 16,122
  • 21
  • 72
  • 136
4
votes
3 answers

Display the complete docstring with docopt without -h

I'm trying to display all the help message with docopt, without adding the --help argument. For example this is from the official doc : """ Naval Fate. Usage: naval_fate ship new ... naval_fate ship move [--speed=] …
ncrocfer
  • 2,432
  • 4
  • 23
  • 37
4
votes
3 answers

How to have the docstring respect the PEP257, while usable with docopt to comply with i18n using gettext?

According to PEP 257 the docstring of command line script should be its usage message: The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the script is invoked with incorrect or missing arguments…
zmo
  • 22,917
  • 4
  • 48
  • 82
4
votes
2 answers

Option multiplicity with docopt

I would like to using docopt for parsing a command line that can receive the same option multiple times. Could somebody explain me how to do it? A test example: #!/usr/bin/env python """ Test program. Usage: test.py -v Options: -v Flag…
André Anjos
  • 3,166
  • 24
  • 31
3
votes
1 answer

Accepting more than one value for more than one argument causes unexpected result

I have the following docopt __doc__ : """gene_sense_distribution_to_csv Usage: gene_sense_distribution_to_csv.py ... [--min_count=] [--gene_regions=] gene_sense_distribution_to_csv.py -h | --help …
Eliran Turgeman
  • 758
  • 2
  • 3
  • 19
3
votes
1 answer

python3 docopt throws usage error while using pyCharm

I need some basic help on docopt with python3.7 .I am using in pyCharm. I tried to let run the example code which is shown on the docopt.org website. But the system is throwing usage errors. I installed the doctop through pip install docopt an have…
Dshoon
  • 31
  • 4
3
votes
3 answers

Option with two arguments with docopt

I want to have an option that takes two arguments. I.e. would like to be able to use $ ./foo --path "old" "new" Or what I really want is: $ ./foo --path "old" "new" --path "old" "new" But I don't know how to do it? (In fact I fear that it might…
Tom de Geus
  • 4,312
  • 2
  • 22
  • 51
3
votes
1 answer

Accepting arbitrary options from docopt

Looking through the docopt documentation and examples I can't seem to find this functionality, but I feel as it should exist so I thought I'd ask to make sure. I'm using docopt for Python and want to be able to allow arbitrary options. The use case…
freebie
  • 1,689
  • 2
  • 15
  • 27
1
2 3
9 10