I am trying to use the docopt
module in Python to parse command-line arguments for a script. This script may be called directly, or via a .exe built with PyInstaller. I want to use the actual name of the program in the usage section, which is different based on how the program is called (note that there are lots more mutually exclusive options here, that I have elided away):
> py script.py
Usage:
script.py -foo <foo>
script.py -bar <bar>
...
> dist/script.exe
Usage:
dist/script.exe -foo <foo>
dist/script.exe -bar <bar>
...
I can do this by using .format()
on the string passed to docopt, but this gets ugly and prevents specifying the options as the module docstring:
doc = """
Usage:
{} -foo <foo>
{} -bar <bar>
...
""".format(sys.argv[0], sys.argv[0])
args = docopt(doc, ...)
Is there a better way?