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.