Commit 19f8da6101c866bf08628f9d16a8aee80bba9522

Authored by Henry Schreiner
Committed by GitHub
1 parent 983993fc

Making CLI11_PARSE the recommended way to run

Showing 1 changed file with 11 additions and 8 deletions
README.md
... ... @@ -58,7 +58,7 @@ So, this library was designed to provide a great syntax, good compiler compatibi
58 58  
59 59 ## Features not supported by this library
60 60  
61   -There are some other possible features that are intentionally not supported by this library:
  61 +There are some other possible "features" that are intentionally not supported by this library:
62 62  
63 63 * Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library.
64 64 * Completion of partial options, such as Python's `argparse` supplies for incomplete arguments. It's better not to guess. Most third party command line parsers for python actually reimplement command line parsing rather than using argparse because of this perceived design flaw.
... ... @@ -72,7 +72,7 @@ There are some other possible features that are intentionally not supported by t
72 72 To use, there are two methods:
73 73  
74 74 1. Copy `CLI11.hpp` from the [most recent release][Github Releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately.
75   -2. Checkout the repository and add as a subdirectory for CMake. You can use the `CLI11` interface target when linking. (CMake 3.4+ recommended) Or, instead of explicitly downloading the library, use the `AddCLI.cmake` supplied in [CLIUtils cmake helpers][cltools-cmake].
  75 +2. Checkout the repository and add as a subdirectory for CMake. You can use the `CLI11` interface target when linking. (CMake 3.4+ required, 3.10+ best) Or, instead of explicitly downloading the library, use the `AddCLI.cmake` supplied in [CLIUtils cmake helpers][cltools-cmake].
76 76  
77 77 To build the tests, checkout the repository and use CMake:
78 78  
... ... @@ -94,14 +94,17 @@ CLI::App app{"App description"};
94 94 std::string filename = "default";
95 95 app.add_option("-f,--file", filename, "A help string");
96 96  
97   -try {
98   - app.parse(argc, argv);
99   -} catch (const CLI::ParseError &e) {
100   - return app.exit(e);
101   -}
  97 +CLI11_PARSE(app, argc, argv);
102 98 ```
103 99  
104   -> Note: The final five lines are so common, they have a dedicated macro: `CLI11_PARSE(app, argc, argv)`.
  100 +> Note: If you don't like macros, this is what that macro expands to:
  101 +> ```cpp
  102 +> try {
  103 +> app.parse(argc, argv);
  104 +> } catch (const CLI::ParseError &e) {
  105 +> return app.exit(e);
  106 +> }
  107 +> ```
105 108  
106 109  
107 110 The initialization is just one line, adding options is just two each. The try/catch block ensures that `-h,--help` or a parse error will exit with the correct return code (selected from `CLI::ExitCodes`). (The return here should be inside `main`). After the app runs, the filename will be set to the correct value if it was passed, otherwise it will be set to the default. You can check to see if this was passed on the command line with `app.count("--file")`.
... ...