8000 README: more formatting updates · patrickjwhite/docopt.cpp@ea59a92 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea59a92

Browse files
committed
README: more formatting updates
1 parent bdb94d6 commit ea59a92

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

README.rst

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ API
102102

103103
docopt::docopt(doc, argv, help /* =true */, version /* ="" */, options_first /* =false */)
104104
105-
``docopt`` takes 1 required and 4 optional arguments:
105+
``docopt`` takes 2 required and 3 optional arguments:
106106

107107
- ``doc`` is a string that contains a **help message** that will be parsed to
108108
create the option parser. The simple rules of how to write such a
@@ -112,7 +112,7 @@ API
112112

113113
.. code:: c++
114114

115-
R"(Usage: my_program.py [-hso FILE] [--quiet | --verbose] [INPUT ...]
115+
R"(Usage: my_program [-hso FILE] [--quiet | --verbose] [INPUT ...]
116116

117117
-h --help show this
118118
-s --sorted sorted output
@@ -173,14 +173,26 @@ the return dictionary will be:
173173
"<x>": "100", "shoot": false,
174174
"<y>": "150"}
175175
176+
If any parsing error (in either the usage, or due to incorrect user inputs) is
177+
encountered, the program will exit with exit code -1.
178+
179+
Note that there is another function that does not exit on error, and instead will
180+
propogate an exception that you can catch and process as you like. See the docopt.h file
181+
for information on the exceptions and usage:
182+
183+
.. code:: c++
184+
185+
docopt::docopt_parse(doc, argv, help /* =true */, version /* =true */, options_first /* =false)
186+
187+
176188
Help message format
177189
---------------------------------------------------
178190

179191
Help message consists of 2 parts:
180192

181193
- Usage pattern, e.g.::
182194

183-
Usage: my_program.py [-hso FILE] [--quiet | --verbose] [INPUT ...]
195+
Usage: my_program [-hso FILE] [--quiet | --verbose] [INPUT ...]
184196

185197
- Option descriptions, e.g.::
186198

@@ -219,8 +231,8 @@ exclusive patterns:
219231
Each pattern can consist of the following elements:
220232

221233
- **<arguments>**, **ARGUMENTS**. Arguments are specified as either
222-
upper-case words, e.g. ``my_program.py CONTENT-PATH`` or words
223-
surrounded by angular brackets: ``my_program.py <content-path>``.
234+
upper-case words, e.g. ``my_program CONTENT-PATH`` or words
235+
surrounded by angular brackets: ``my_program <content-path>``.
224236
- **--options**. Options are words started with dash (``-``), e.g.
225237
``--output``, ``-o``. You can "stack" several of one-letter
226238
options, e.g. ``-oiv`` which will be the same as ``-o -i -v``. The
@@ -236,23 +248,23 @@ Each pattern can consist of the following elements:
236248

237249
Use the following constructs to specify patterns:
238250

239-
- **[ ]** (brackets) **optional** elements. e.g.: ``my_program.py
251+
- **[ ]** (brackets) **optional** elements. e.g.: ``my_program
240252
[-hvqo FILE]``
241253
- **( )** (parens) **required** elements. All elements that are *not*
242-
put in **[ ]** are also required, e.g.: ``my_program.py
243-
--path=<path> <file>...`` is the same as ``my_program.py
254+
put in **[ ]** are also required, e.g.: ``my_program
255+
--path=<path> <file>...`` is the same as ``my_program
244256
(--path=<path> <file>...)``. (Note, "required options" might be not
245257
a good idea for your users).
246258
- **|** (pipe) **mutually exclusive** elements. Group them using **(
247259
)** if one of the mutually exclusive elements is required:
248-
``my_program.py (--clockwise | --counter-clockwise) TIME``. Group
260+
``my_program (--clockwise | --counter-clockwise) TIME``. Group
249261
them using **[ ]** if none of the mutually-exclusive elements are
250-
required: ``my_program.py [--left | --right]``.
262+
required: ``my_program [--left | --right]``.
251263
- **...** (ellipsis) **one or more** elements. To specify that
252264
arbitrary number of repeating elements could be accepted, use
253-
ellipsis (``...``), e.g. ``my_program.py FILE ...`` means one or
265+
ellipsis (``...``), e.g. ``my_program FILE ...`` means one or
254266
more ``FILE``-s are accepted. If you want to accept zero or more
255-
elements, use brackets, e.g.: ``my_program.py [FILE ...]``. Ellipsis
267+
elements, use brackets, e.g.: ``my_program [FILE ...]``. Ellipsis
256268
works as a unary operator on the expression to the left.
257269
- **[options]** (case sensitive) shortcut for any options. You can
258270
use it if you want to specify that the usage pattern could be
@@ -268,7 +280,7 @@ Use the following constructs to specify patterns:
268280
If your pattern allows to match argument-less option (a flag) several
269281
times::
270282

271-
Usage: my_program.py [-v | -vv | -vvv]
283+
Usage: my_program [-v | -vv | -vvv]
272284

273285
then number of occurrences of the option will be counted. I.e.
274286
``args['-v']`` will be ``2`` if program was invoked as ``my_program
@@ -278,9 +290,9 @@ If your usage patterns allows to match same-named option with argument
278290
or positional argument several times, the matched arguments will be
279291
collected into a list::
280292

281-
Usage: my_program.py <file> <file> --path=<path>...
293+
Usage: my_program <file> <file> --path=<path>...
282294

283-
I.e. invoked with ``my_program.py file1 file2 --path=./here
295+
I.e. invoked with ``my_program file1 file2 --path=./here
284296
--path=./there`` the returned dict will contain ``args['<file>'] ==
285297
['file1', 'file2']`` and ``args['--path'] == ['./here', './there']``.
286298

@@ -337,7 +349,7 @@ The rules are as follows:
337349
will be interpreted as string. If it *is* repeatable, it will be
338350
splited into a list on whitespace::
339351

340-
Usage: my_program.py [--repeatable=<arg> --repeatable=<arg>]
352+
Usage: my_program [--repeatable=<arg> --repeatable=<arg>]
341353
[--another-repea 6D4E table=<arg>]...
342354
[--not-repeatable=<arg>]
343355

@@ -378,20 +390,34 @@ Compiling the example / Running the tests
378390
The original Python module includes some language-agnostic unit tests,
379391
and these can be run with this port as well.
380392

381-
For example, with the clang compiler on OSX::
393+
The tests are a Python driver that uses the testcases.docopt file to then invoke
394+
a C++ test case runner (run_testcase.cpp)::
382395

383396
$ clang++ --std=c++11 --stdlib=libc++ docopt.cpp run_testcase.cpp -o run_testcase
384397
$ python run_tests.py
385398
PASS (175)
386399

387-
You can also compile the example show at the start (also included as
388-
example.cpp)::
400+
You can also compile the example shown at the start (included as example.cpp)::
389401

390-
$ clang++ clang++ --std=c++11 --stdlib=libc++ -I . docopt.cpp examples/naval_fate.cpp -o naval_fate
402+
$ clang++ --std=c++11 --stdlib=libc++ -I . docopt.cpp examples/naval_fate.cpp -o naval_fate
391403
$ ./naval_fate --help
392404
[ ... ]
393405
$ ./naval_fate ship Guardian move 100 150 --speed=15
394-
[ ... ]
406+
--drifting: false
407+
--help: false
408+
--moored: false
409+
--speed: "15"
410+
--version: false
411+
<name>: ["Guardian"]
412+
<x>: "100"
413+
<y>: "150"
414+
mine: false
415+
move: true
416+
new: false
417+
remove: false
418+
set: false
419+
ship: true
420+
shoot: false
395421

396422
Development
397423
---------------------------------------------------

0 commit comments

Comments
 (0)
0