1
- ``docopt.cpp ``: a C++11 port for docopt-py
1
+ ``docopt.cpp ``: a C++11 port of docopt
2
2
======================================================================
3
3
4
4
Isn't it awesome how ``getopt `` (and ``boost::program_options `` for you fancy
@@ -40,10 +40,11 @@ and instead can write only the help message--*the way you want it*.
40
40
41
41
int main(int argc, const char** argv)
42
42
{
43
- std::map<std::string, docopt::value> args = docopt::docopt(USAGE,
44
- { argv + 1, argv + argc },
45
- true, // show help if requested
46
- "Naval Fate 2.0"); // version string
43
+ std::map<std::string, docopt::value> args
44
+ = docopt::docopt(USAGE,
45
+ { argv + 1, argv + argc },
46
+ true, // show help if requested
47
+ "Naval Fate 2.0"); // version string
47
48
48
49
for(auto const& arg : args) {
49
50
std::cout << arg.first << arg.second << std::endl;
@@ -70,9 +71,9 @@ original.
70
71
This port is written in C++11 and also requires a good C++11 standard library
71
72
(in particular, one with ``regex `` support). The following compilers should
72
73
be able to handle this:
73
- * clang 3.3
74
- * gcc 4.9 (If someone can verify this, or provide patches, that would be great!)
75
- * Visual C++ 2013 will almost certainly *not * compile this code. Hopefully next year.
74
+ * clang 3.3
75
+ * gcc 4.9 (If someone can verify this, or provide patches, that would be great!)
76
+ * Visual C++ 2013: will *not * compile this code. Hopefully next year.
76
77
77
78
This port is licensed under the MIT license, just like the original module.
78
79
However, we are also dual-licensing this code under the Boost License, version 1.0,
@@ -153,7 +154,7 @@ arguments and commands as keys, spelled exactly like in your help message.
153
154
Long versions of options are given priority. For example, if you invoke the
154
155
top example as::
155
156
156
- naval_fate.py ship Guardian move 100 150 --speed=15
157
+ naval_fate ship Guardian move 100 150 --speed=15
157
158
158
159
the return dictionary will be:
159
160
@@ -196,7 +197,7 @@ Minimum example:
196
197
197
198
.. code :: python
198
199
199
- """ Usage: my_program.py
200
+ """ Usage: my_program
200
201
201
202
"""
202
203
@@ -206,8 +207,8 @@ exclusive patterns:
206
207
207
208
.. code :: python
208
209
209
- """ Usage: my_program.py FILE
210
- my_program.py COUNT FILE
210
+ """ Usage: my_program FILE
211
+ my_program COUNT FILE
211
212
212
213
"""
213
214
@@ -356,24 +357,6 @@ source if in doubt.
356
357
There are also very intersting applications and ideas at that page.
357
358
Check out the sister project for more information!
358
359
359
- Compiling the code and running the tests
360
- ----------------------------------------------------------------------
361
- The original Python module includes some language-agnostic unit tests,
362
- and these can be run with this port as well.
363
-
364
- For example, with the clang compiler on OSX:
365
- $ clang++ --std=c++11 --stdlib=libc++ docopt.cpp run_testcase.cpp -o run_testcase
366
- $ python run_tests.py
367
- PASS (175)
368
-
369
- You can also compile the example show at the start (also included as
370
- example.cpp):
371
- $ clang++ clang++ --std=c++11 --stdlib=libc++ -I . docopt.cpp examples/naval_fate.cpp -o naval_fate
372
- $ ./naval_fate --help
373
- [ ... ]
374
- $ ./naval_fate ship Guardian move 100 150 --speed=15
375
- [ ... ]
376
-
377
360
Subparsers, multi-level help and *huge * applications (like git)
378
361
----------------------------------------------------------------------
379
362
@@ -386,6 +369,24 @@ we implemented a subset of git command-line interface as an example:
386
369
`examples/git
387
370
<https://github.com/docopt/docopt/tree/master/examples/git> `_
388
371
372
+ Compiling the code and running the tests
373
+ ----------------------------------------------------------------------
374
+ The original Python module includes some language-agnostic unit tests,
375
+ and these can be run with this port as well.
376
+
377
+ For example, with the clang compiler on OSX:
378
+ $ clang++ --std=c++11 --stdlib=libc++ docopt.cpp run_testcase.cpp -o run_testcase
379
+ $ python run_tests.py
380
+ PASS (175)
381
+
382
+ You can also compile the example show at the start (also included as
383
+ example.cpp):
384
+ $ clang++ clang++ --std=c++11 --stdlib=libc++ -I . docopt.cpp examples/naval_fate.cpp -o naval_fate
385
+ $ ./naval_fate --help
386
+ [ ... ]
387
+ $ ./naval_fate ship Guardian move 100 150 --speed=15
388
+ [ ... ]
389
+
389
390
Development
390
391
======================================================================
391
392
0 commit comments