0

I am using the module docopt but need to have line-wrapping in the main docstring of my programs. In order to pass this line-wrapped docstring to docopt, I want to 'unwrap' the lines of my docstring in a sensible and robust way such that docopt can interpret it easily.

The type of docstring I have is as follows:

Usage:
    program [options]

Options:
    -h, --help                 display help message
    --version                  display version and exit
    -v, --verbose              verbose logging
    -u, --username=USERNAME    username
    -c, --configuration=FILE   file containing configuration
                               [default: 2015-02-06T1012Z_test.txt]
    -d, --data=FILE            file containing list of data files generated in
                               Run 1 of the LHC
                               [default: 2015-02-05T1012Z_data.root]

You can see that I have some nice wrapping of the text in the right field: long descriptions are wrapped and the default values in square brackets can optionally be placed on new lines for clarity. I want to process this docstring such that it becomes the following:

Usage:
    program [options]

Options:
    -h, --help                 display help message
    --version                  display version and exit
    -v, --verbose              verbose logging
    -u, --username=USERNAME    username
    -c, --configuration=FILE   file containing configuration [default: 2015-02-06T1012Z_test.txt]
    -d, --data=FILE            file containing list of data files generated in Run 1 of the LHC [default: 2015-02-05T1012Z_data.root]

I imagine that one approach would be to detect lines after "Options:" that do not feature "-" as the first character after some whitespace and pull those lines back to the previous line, but I'm both not sure if this is a robust appoach and not sure how to implement this efficiently. I would welcome some guidance.

georg
  • 211,518
  • 52
  • 313
  • 390
d3pd
  • 7,935
  • 24
  • 76
  • 127
  • 1
    According to [this answer](http://stackoverflow.com/a/16863372/3001761), `docopt` can handle multi-line descriptions - have you had an issue with this? – jonrsharpe Feb 20 '15 at 11:13
  • 1
    Well, you're absolutely right. Every guide I've seen implemented the docstring without line-wrapping. It works just fine. Thanks! – d3pd Feb 20 '15 at 12:44

0 Answers0