Files
CLI11/book
Uilian Ries f4f225d9a2 docs: Add Conan installation in the documentation (#1061)
Greetings, fellow CLI11 community!

We have just added the latest version of cli11 to [Conan
Center](https://conan.io/center/recipes/cli11?version=2.4.2) and thought
it would be a nice addition to include instructions on how to install
CLI11 via Conan in the book folder.

Please let me know if this is okay, or if you would prefer it placed
elsewhere.

**UPDATE**: Some extra information to be more clear about the used
command line and links:

I did not mention how to install/configure Conan, because both links to
conan.io and conan-center-index has all Conan documentation updated. For
instance: https://conan.io/downloads

The latest version of CLI11 available in Conan Center is 2.4.2:

- https://conan.io/center/recipes/cli11?version=2.4.2

or, can be found by running the conan command:

    conan search "cli11"

The command `conan install --requires="cli11/[*]" --build=missing`
means:

* conan install: Install a package from a remote. By default, it points
to the official Conan Center
* --requires="cli11/[*]": Install the latest version of CLI11 available
in Conan Center
* --build=missing: In case not finding a pre-built package compatible,
build it from source then.


Regards!

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-10 15:17:38 -07:00
..
2021-06-15 14:52:40 -04:00
2019-09-06 14:25:27 -04:00
2022-05-10 13:47:38 -04:00
2021-06-15 14:52:40 -04:00
2023-06-28 16:11:34 -04:00
2022-05-10 13:47:38 -04:00
2022-05-10 13:47:38 -04:00

CLI11: An introduction

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

The 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, this tutorial book, and more technical API docs.

Feel free to contribute to this documentation here if something can be improved!

The 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:

gitbook $ ./a.out
Parameter value: 0

gitbook $ ./a.out -p 4
Parameter value: 4

gitbook $ ./a.out --help
App description
Usage: ./a.out [OPTIONS]

Options:
  -h,--help                   Print this help message and exit
  -p INT                      Parameter

Like any good command line application, help is provided. This program can be implemented in 10 lines:

include

Source code

Unlike 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:

gitbook:examples $ c++ -std=c++11 intro.cpp

Much more complicated options are handled elegantly:

std::string file;
app.add_option("-f,--file", file, "Require an existing file")
  ->required()
  ->check(CLI::ExistingFile);

You 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.

You 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.

Reading/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.

CLI11 was developed at the University of Cincinnati in support of the GooFit library under NSF Award 1414736. It was featured in a DIANA/HEP meeting at CERN. Please give it a try! Feedback is always welcome.