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
2
votes
1 answer

docopt does not parse args, just prints usage

I cannot get docopt to work. I have this simple example, which as far as I can tell is correct: #! /usr/bin/env python3 """usage: do.py name """ from docopt import docopt args = docopt(__doc__) print(f"Hello, {args['name']}!") and it only ever…
user1832047
  • 155
  • 9
2
votes
1 answer

Docopt/Python, how to properly test a function

Can anyone help me run this test please. I have made a simple python app with docopt. I have a function called find_by_zip in find_store.py usage = ''' Store Finder CLI. Usage: find_store --address="
" find_store…
Generaldeep
  • 437
  • 2
  • 12
  • 30
2
votes
1 answer

Multiple positional and optional arguments using docopt

I'm trying to implement a python3 CLI using the docopt package. I'm trying to get my program accept multiple positional input files and, optionally a list of output files. A MWE for my docstring is: __doc__ = """ Usage: test.py…
Torilla
  • 383
  • 5
  • 16
2
votes
1 answer

How does the type deduction work in this Docopt example?

Take a look at this code using the docopt library: const USAGE: &'static str = "...something..."; #[derive(Deserialize)] struct Args { flag: bool, } type Result = result::Result>; fn main() { let mut…
saga
  • 1,933
  • 2
  • 17
  • 44
2
votes
1 answer

Use parameter mutliple time but with limit in docopt

I want to format my command usage with docopt. I found out that ... means that you can write a parameter multiple time. My problem is, that I have an argument that you can repeat multiple times but it has a limit. I don't want to…
l0c4lh057
  • 41
  • 1
  • 7
2
votes
1 answer

How to force at least one argument from a set in Docopt?

I want my program to require at least one argument from a set in order for the arguments to be valid. So for the sake of example, let's say I have 3 switches (-a, -b and -c) and two mandatory arguments. These would be valid. myapp -a FOO BAR myapp…
Jake
  • 1,701
  • 3
  • 23
  • 44
2
votes
1 answer

Why does docopt exits the script after parsing the parameters?

I use docopt for some time now and on a new script I cannot manage to pass through the argument parsing: # coding=utf-8 """ API server for the infoscreen frontends Usage: python3 webserver.py [options] Options: --bind ADDRESS address to…
WoJ
  • 27,165
  • 48
  • 180
  • 345
2
votes
2 answers

Why is a parameter parsed as a bool?

I usually use docopt to handle the command line parameters but I now have a case where the parameters is parsed unexpectedly (it must be a silly mistake of mine as it always works great) """ API to do something Usage: api.py…
WoJ
  • 27,165
  • 48
  • 180
  • 345
2
votes
1 answer

mutually_exclusive_group with optional and positional argument

I created an cli specification with docopt which works great, however for some reason I have to rewrite it to argparse Usage: update_store_products ... update_store_products --all Options: -a --all Updates all…
noisy
  • 6,495
  • 10
  • 50
  • 92
2
votes
1 answer

Better solution than if __name__ == '__main__' twice in Python script

I have multiple Python scripts which use docopt. My issue is that the available options for the two scripts differ slightly - one option is present in one script, but not the other. I've included a minimum working example below. If I run: python…
Matthew
  • 1,179
  • 2
  • 12
  • 16
2
votes
2 answers

docopt linker error for example program

I am trying to compile the example code from the github page of docopt. I am getting a linker error though: /tmp/test-d3ed6b.o: In function `main': test.cpp:(.text+0xf3): undefined reference to `docopt::docopt(std::string const&,…
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
2
votes
0 answers

List flag once but input multiple files

""" Usage: program (--opt=OPT...) (--ano=ANO...) Options: --opt=OPT An option that can be specified multiple times to form a list --ano=ANO An option that can be specified multiple times to form a list """ import docopt print…
The Unfun Cat
  • 29,987
  • 31
  • 114
  • 156
2
votes
1 answer

docopt.go weird error message

using docopt.go to refactor an old project and minimalise code the program looks like this package main import ( "fmt" "github.com/docopt/docopt.go" ) const Version = `2.0` const Usage = ` Usage: serve [--port] serve help |…
user2693845
2
votes
2 answers

How do I make an argument with unknown n number of values stored in an array when parsed using docopt

I want a command line argument to be in an array format. i.e myprogram.py -a 1,2,4,5 and when the argument is parsed using docopt, I want to see: {'a' = [1,2,4,5]} # the length of this array could be as long as user may like. I don't know if this…
Dhruv Patel
  • 426
  • 3
  • 9
  • 19
2
votes
1 answer

How to pass a docopt argument where the argument is a string with spaces in python

How do I crate a docopt in python where my argument needs to be a string with spaces. I tried putting single and double quotes around it but it doesn't work. This is my docopt string so far. """ Parser Usage: parser.py
Dhruv Patel
  • 426
  • 3
  • 9
  • 19
1 2
3
9 10