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

147 questions
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
  • 4,641
  • 2
  • 27
  • 34
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
  • 1,526
  • 2
  • 16
  • 34
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
  • 5
3
votes
2 answers

ModuleNotFoundError: No module named 'docopt'

I have installed docopt by typing pip3 install docopt and now it is well installed: You can see it on the list umr5558-c02gl0y6drjm:Concatenate etudiant$ pip3 list Package Version --------------- ------- biopython 1.71 buildozer …
Grendel
  • 555
  • 1
  • 4
  • 11
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
  • 2,161
  • 2
  • 19
  • 36
3
votes
1 answer

Trouble implementing repeating elements in docopt

I'm using docopt to parse command line input in python. I have my docstring: """ Usage: docoptTest.py [options] Options: -h --help show this help message and exit -n --name The name of the specified…
polarbits
  • 187
  • 1
  • 3
  • 10
3
votes
1 answer

Why does docopt fail with docopt.DocoptLanguageError: unmatched '['?

Why does this code fail with the following exception? """my_program - for doing awesome stuff Usage: my_program [--foo] Options: --foo - this will do foo """ import docopt args = docopt.docopt(doc=__doc__) Exception: Traceback (most recent…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
3
votes
2 answers

How to save a previous command line argument

I'm writing my first python command line tool using docopt and have run into an issue. My structure is like this: Usage: my-tool configure my-tool [(-o
mdegges
  • 963
  • 3
  • 18
  • 39
3
votes
1 answer

How to set only specific values for a parameter in docopt python?

I am trying to use docopt for a python code. I actually need to set only specific values for a parameter. My usage is as below: """ Usage: test.py --list=(all|available) Options: list Choice to list devices (all / available) """ I've tried…
3
votes
1 answer

docopt on python 3 only prints help screen and does not execute the function

I am using docopt in Python 3 for the first time. When I run the code, the output only displays the Usage option data, and does not execute the function in the module. Here is an example. I have this code in a file. """Usage: scratch.py [-h]…
krishnab
  • 9,270
  • 12
  • 66
  • 123
3
votes
1 answer

How can text in the options configuration of Docopt be wrapped?

I have a few detailed option specifications in the docstring used for configuration of Docopt. Some of the items are quite lengthy. Is there a way of wrapping the text to make it more legible or to make it fit to a line width more easily? Let's say…
d3pd
  • 7,935
  • 24
  • 76
  • 127
3
votes
2 answers

Docopt accepts multi args in middle?

I want my script accepts command line args like "cp" command does: ''' Usage: cp.py ... cp.py -t ... cp.py -s ... -t ''' Those command line $ python cp.py src/path/1 src/path/2…
TylerTemp
  • 970
  • 1
  • 9
  • 9
3
votes
1 answer

Testing A Docopt command-line app In Unittest?

can anyone show me how can I test a cli app written in Docopt (Python)? Someone on GitHub posted this, import unittest from docopt import docopt import your.entry.point.of.sum as sum # you can import the doc string from the sum module doc =…
Delete Me
  • 111
  • 1
  • 4
  • 12
3
votes
1 answer

docopt not allowing optional arguments

I have the following usage in docopt: cli.py add_user [] cli.py remove_user (--id|--username) Where [] is an optional argument. However, when I…
TomSelleck
  • 6,706
  • 22
  • 82
  • 151
3
votes
0 answers

Optional parameter not working on schema

I am adding validation using schema for CLI that uses docopt, but I cannot seem to get optional to work. I want to validate that: the input file exists valid options are used if the PATH is added that the directory exists. Here is app so…
edbeck
  • 61
  • 5
1
2
3
9 10