• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

chapters/H18-Oct-2021-1,280902

code/H03-May-2022-11670

.gitignoreH A D18-Oct-2021369 2115

README.mdH A D18-Oct-20213.7 KiB6645

SUMMARY.mdH A D18-Oct-2021553 1614

book.jsonH A D18-Oct-2021338 1716

README.md

1# CLI11: An introduction
2
3This gitbook is designed to provide an introduction to using the CLI11 library to write your own command line programs. The library is designed to be clean, intuitive, but powerful. There are no requirements beyond C++11 support (and even `<regex>` support not required). It works on Mac, Linux, and Windows, and has 100% test coverage on all three systems. You can simply drop in a single header file (`CLI11.hpp` available in [releases][]) to use CLI11 in your own application. Other ways to integrate it into a build system are listed in the [README][].
4
5The library was inspired the Python libraries [Plumbum][] and [Click][], and incorporates many of their user friendly features. The library is extensively documented, with a [friendly introduction][README], this tutorial book, and more technical [API docs][].
6
7> Feel free to contribute to [this documentation here][CLI11Tutorial] if something can be improved!
8
9The syntax is simple and scales from a basic application to a massive physics analysis with multiple models and many parameters and switches. For example, this is a simple program that has an optional parameter that defaults to 0:
10
11```term
12gitbook $ ./a.out
13Parameter value: 0
14
15gitbook $ ./a.out -p 4
16Parameter value: 4
17
18gitbook $ ./a.out --help
19App description
20Usage: ./a.out [OPTIONS]
21
22Options:
23  -h,--help                   Print this help message and exit
24  -p INT                      Parameter
25```
26
27Like any good command line application, help is provided. This program can be implemented in 10 lines:
28
29[include](code/intro.cpp)
30
31[Source code](https://github.com/CLIUtils/CLI11/blob/main/book/code/intro.cpp)
32
33Unlike some other libraries, this is enough to exit correctly and cleanly if help is requested or if incorrect arguments are passed. You can try this example out for yourself. To compile with GCC:
34
35```term
36gitbook:examples $ c++ -std=c++11 intro.cpp
37```
38
39Much more complicated options are handled elegantly:
40
41```cpp
42std::string file;
43app.add_option("-f,--file", file, "Require an existing file")
44  ->required()
45  ->check(CLI::ExistingFile);
46```
47
48You can use any valid type; the above example could have used a `boost::file_system` file instead of a `std::string`. The value is a real value and does not require any special lookups to access. You do not have to risk typos by repeating the values after parsing like some libraries require. The library also handles positional arguments, flags, fixed or unlimited repeating options, interdependent options, flags, custom validators, help groups, and more.
49
50You can use subcommands, as well. Subcommands support callback lambda functions when parsed, or they can be checked later. You can infinitely nest subcommands, and each is a full `App` instance, supporting everything listed above.
51
52Reading/producing `.ini` files for configuration is also supported, as is using environment variables as input. The base `App` can be subclassed and customized for use in a toolkit (like [GooFit][]). All the standard shell idioms, like `--`, work as well.
53
54CLI11 was developed at the [University of Cincinnati][] in support of the [GooFit][] library under [NSF Award 1414736][NSF 1414736]. It was featured in a [DIANA/HEP][] meeting at CERN. Please give it a try! Feedback is always welcome.
55
56[goofit]: https://github.com/GooFit/GooFit
57[diana/hep]: https://diana-hep.org
58[cli11tutorial]: https://cliutils.github.io/CLI11/book
59[releases]: https://github.com/CLIUtils/CLI11/releases
60[api docs]: https://cliutils.github.io/CLI11
61[readme]: https://github.com/CLIUtils/CLI11/blob/main/README.md
62[nsf 1414736]: https://nsf.gov/awardsearch/showAward?AWD_ID=1414736
63[university of cincinnati]: https://www.uc.edu
64[plumbum]: https://plumbum.readthedocs.io/en/latest/
65[click]: https://click.palletsprojects.com
66