11``docopt.cpp ``: A C++11 Port
22============================
3+
4+ Contents
5+ --------
6+
7+ .. contents ::
8+ :local:
9+ :depth: 3
10+
311docopt creates *beautiful * command-line interfaces
412--------------------------------------------------
513
@@ -58,13 +66,40 @@ and instead can write only the help message--*the way you want it*.
5866Beat that! The option parser is generated based on the docstring above
5967that is passed to ``docopt::docopt `` function. ``docopt `` parses the usage
6068pattern (``"Usage: ..." ``) and option descriptions (lines starting
61- with dash "``- ``") and ensures that the program invocation matches the
69+ with a dash "``- ``") and ensures that the program invocation matches the
6270usage pattern; it parses options, arguments and commands based on
6371that. The basic idea is that *a good help message has all necessary
6472information in it to make a parser *.
6573
74+ Getting and using
75+ -----------------
76+
77+ To get *docopt.cpp *, the simplest is to use `Conda <https://github.com/conda-forge/docopt.cpp-feedstock >`_::
78+
79+ conda install -c conda-forge docopt.cpp
80+
81+ Alternatively manual installation is done using (unix)::
82+
83+ git clone
84+ cmake .
85+ make install
86+
87+ To link *docopt.cpp *, the simplest is to use CMake. The general structure of your
88+ ``CMakeLists.txt `` would be as follows::
89+
90+ cmake_minimum_required(VERSION 3.1)
91+
92+ project(example)
93+
94+ find_package(docopt COMPONENTS CXX REQUIRED)
95+ include_directories(${DOCOPT_INCLUDE_DIRS})
96+
97+ add_executable(${PROJECT_NAME} ...)
98+
99+ target_link_libraries(${PROJECT_NAME} docopt)
100+
66101C++11 port details
67- ---------------------------------------------------
102+ ------------------
68103
69104This is a port of the ``docopt.py `` module (https://github.com/docopt/docopt),
70105and we have tried to maintain full feature parity (and code structure) as the
@@ -80,7 +115,7 @@ to work with docopt:
80115
81116GCC-4.8 can work, but the std::regex module needs to be replaced with ``Boost.Regex ``.
82117In that case, you will need to define ``DOCTOPT_USE_BOOST_REGEX `` when compiling
83- docopt, and link your code with the appropriated Boost libraries. A relativley
118+ docopt, and link your code with the appropriated Boost libraries. A relatively
84119recent version of Boost is needed: 1.55 works, but 1.46 does not for example.
85120
86121This port is licensed under the MIT license, just like the original module.
@@ -101,7 +136,7 @@ The differences from the Python port are:
101136 some of the regex's had to be restructured and additional loops used.
102137
103138API
104- ---------------------------------------------------
139+ ---
105140
106141.. code :: c++
107142
@@ -182,16 +217,15 @@ If any parsing error (in either the usage, or due to incorrect user inputs) is
182217encountered, the program will exit with exit code -1.
183218
184219Note that there is another function that does not exit on error, and instead will
185- propogate an exception that you can catch and process as you like. See the docopt.h file
220+ propagate an exception that you can catch and process as you like. See the docopt.h file
186221for information on the exceptions and usage:
187222
188223.. code :: c++
189224
190225 docopt::docopt_parse(doc, argv, help /* =true */, version / * =true */, options_first / * =false)
191226
192-
193227Help message format
194- ---------------------------------------------------
228+ -------------------
195229
196230Help message consists of 2 parts:
197231
@@ -210,7 +244,7 @@ Help message consists of 2 parts:
210244Their format is described below; other text is ignored.
211245
212246Usage pattern format
213- ----------------------------------------------------------------------
247+ --------------------
214248
215249**Usage pattern ** is a substring of ``doc `` that starts with
216250``usage: `` (case *insensitive *) and ends with a *visibly * empty line.
@@ -263,7 +297,7 @@ Use the following constructs to specify patterns:
263297- **| ** (pipe) **mutually exclusive ** elements. Group them using **(
264298 ) ** if one of the mutually exclusive elements is required:
265299 ``my_program (--clockwise | --counter-clockwise) TIME ``. Group
266- them using **[ ] ** if none of the mutually- exclusive elements are
300+ them using **[ ] ** if none of the mutually exclusive elements are
267301 required: ``my_program [--left | --right] ``.
268302- **... ** (ellipsis) **one or more ** elements. To specify that
269303 arbitrary number of repeating elements could be accepted, use
@@ -291,7 +325,7 @@ then number of occurrences of the option will be counted. I.e.
291325``args['-v'] `` will be ``2 `` if program was invoked as ``my_program
292326-vv ``. Same works for commands.
293327
294- If your usage patterns allows to match same-named option with argument
328+ If your usage pattern allows to match same-named option with argument
295329or positional argument several times, the matched arguments will be
296330collected into a list::
297331
@@ -301,9 +335,8 @@ I.e. invoked with ``my_program file1 file2 --path=./here
301335--path=./there `` the returned dict will contain ``args['<file>'] ==
302336['file1', 'file2'] `` and ``args['--path'] == ['./here', './there'] ``.
303337
304-
305338Option descriptions format
306- ----------------------------------------------------------------------
339+ --------------------------
307340
308341**Option descriptions ** consist of a list of options that you put
309342below your usage patterns.
@@ -328,7 +361,7 @@ The rules are as follows:
328361 argument after space (or equals "``= ``" sign) as shown below. Follow
329362 either <angular-brackets> or UPPER-CASE convention for options'
330363 arguments. You can use comma if you want to separate options. In
331- the example below, both lines are valid, however you are recommended
364+ the example below, both lines are valid. However you are recommended
332365 to stick to a single style.::
333366
334367 -o FILE --output=FILE # without comma, with "=" sign
@@ -352,7 +385,7 @@ The rules are as follows:
352385
353386- If the option is not repeatable, the value inside ``[default: ...] ``
354387 will be interpreted as string. If it *is * repeatable, it will be
355- splited into a list on whitespace::
388+ split into a list on whitespace::
356389
357390 Usage: my_program [--repeatable=<arg> --repeatable=<arg>]
358391 [--another-repeatable=<arg>]...
@@ -368,18 +401,18 @@ The rules are as follows:
368401 --not-repeatable=<arg> [default: ./here ./there]
369402
370403Examples
371- ----------------------------------------------------------------------
404+ --------
372405
373406We have an extensive list of `examples
374407<https://github.com/docopt/docopt/tree/master/examples> `_ which cover
375408every aspect of functionality of **docopt **. Try them out, read the
376409source if in doubt.
377410
378- There are also very intersting applications and ideas at that page.
411+ There are also very interesting applications and ideas at that page.
379412Check out the sister project for more information!
380413
381414Subparsers, multi-level help and *huge * applications (like git)
382- ----------------------------------------------------------------------
415+ ---------------------------------------------------------------
383416
384417If you want to split your usage-pattern into several, implement
385418multi-level help (with separate help-screen for each subcommand),
@@ -391,7 +424,8 @@ we implemented a subset of git command-line interface as an example:
391424<https://github.com/docopt/docopt/tree/master/examples/git> `_
392425
393426Compiling the example / Running the tests
394- ----------------------------------------------------------------------
427+ -----------------------------------------
428+
395429The original Python module includes some language-agnostic unit tests,
396430and these can be run with this port as well.
397431
@@ -425,7 +459,7 @@ You can also compile the example shown at the start (included as example.cpp)::
425459 shoot: false
426460
427461Development
428- ---------------------------------------------------
462+ -----------
429463
430464Comments and suggestions are *very * welcome! If you find issues, please
431465file them and help improve our code!
@@ -436,7 +470,7 @@ we might want to first negotiate these changes into the Python code first.
436470However, bring it up! Let's hear it!
437471
438472Changelog
439- ---------------------------------------------------
473+ ---------
440474
441475**docopt ** follows `semantic versioning <http://semver.org >`_. The
442476first release with stable API will be 1.0.0 (soon).
0 commit comments