Skip to content

Commit 6244119

Browse files
tdegeusjaredgrubb
authored andcommitted
Updating readme: added Conda and CMake instructions; various spelling updates
1 parent 3dd23e3 commit 6244119

File tree

1 file changed

+54
-20
lines changed

1 file changed

+54
-20
lines changed

README.rst

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
``docopt.cpp``: A C++11 Port
22
============================
3+
4+
Contents
5+
--------
6+
7+
.. contents::
8+
:local:
9+
:depth: 3
10+
311
docopt creates *beautiful* command-line interfaces
412
--------------------------------------------------
513

@@ -58,13 +66,40 @@ and instead can write only the help message--*the way you want it*.
5866
Beat that! The option parser is generated based on the docstring above
5967
that is passed to ``docopt::docopt`` function. ``docopt`` parses the usage
6068
pattern (``"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
6270
usage pattern; it parses options, arguments and commands based on
6371
that. The basic idea is that *a good help message has all necessary
6472
information 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+
66101
C++11 port details
67-
---------------------------------------------------
102+
------------------
68103

69104
This is a port of the ``docopt.py`` module (https://github.com/docopt/docopt),
70105
and we have tried to maintain full feature parity (and code structure) as the
@@ -80,7 +115,7 @@ to work with docopt:
80115

81116
GCC-4.8 can work, but the std::regex module needs to be replaced with ``Boost.Regex``.
82117
In 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
84119
recent version of Boost is needed: 1.55 works, but 1.46 does not for example.
85120

86121
This 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

103138
API
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
182217
encountered, the program will exit with exit code -1.
183218

184219
Note 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
186221
for 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-
193227
Help message format
194-
---------------------------------------------------
228+
-------------------
195229

196230
Help message consists of 2 parts:
197231

@@ -210,7 +244,7 @@ Help message consists of 2 parts:
210244
Their format is described below; other text is ignored.
211245

212246
Usage 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
295329
or positional argument several times, the matched arguments will be
296330
collected 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-
305338
Option descriptions format
306-
----------------------------------------------------------------------
339+
--------------------------
307340

308341
**Option descriptions** consist of a list of options that you put
309342
below 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

370403
Examples
371-
----------------------------------------------------------------------
404+
--------
372405

373406
We have an extensive list of `examples
374407
<https://github.com/docopt/docopt/tree/master/examples>`_ which cover
375408
every aspect of functionality of **docopt**. Try them out, read the
376409
source 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.
379412
Check out the sister project for more information!
380413

381414
Subparsers, multi-level help and *huge* applications (like git)
382-
----------------------------------------------------------------------
415+
---------------------------------------------------------------
383416

384417
If you want to split your usage-pattern into several, implement
385418
multi-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

393426
Compiling the example / Running the tests
394-
----------------------------------------------------------------------
427+
-----------------------------------------
428+
395429
The original Python module includes some language-agnostic unit tests,
396430
and 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

427461
Development
428-
---------------------------------------------------
462+
-----------
429463

430464
Comments and suggestions are *very* welcome! If you find issues, please
431465
file them and help improve our code!
@@ -436,7 +470,7 @@ we might want to first negotiate these changes into the Python code first.
436470
However, bring it up! Let's hear it!
437471

438472
Changelog
439-
---------------------------------------------------
473+
---------
440474

441475
**docopt** follows `semantic versioning <http://semver.org>`_. The
442476
first release with stable API will be 1.0.0 (soon).

0 commit comments

Comments
 (0)