Commit 1b02682223b51d8b98a7f68543f905c1d7543121

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent 89c57961

Adding some info to docs

CHANGELOG.md
  1 +## Version 1.3 (in progress)
  2 +* `parse` no longer returns (so `CLI11_PARSE` is always usable) [#37](https://github.com/CLIUtils/CLI11/pull/37)
  3 +* Added `remaining()` and `remaining_size()` [#37](https://github.com/CLIUtils/CLI11/pull/37)
  4 +* `allow_extras` and `prefix_command` are now valid on subcommands [#37](https://github.com/CLIUtils/CLI11/pull/37)
  5 +
1 ## Version 1.2 6 ## Version 1.2
2 7
3 * Added functional form of flag [#33](https://github.com/CLIUtils/CLI11/pull/33), automatic on C++14 8 * Added functional form of flag [#33](https://github.com/CLIUtils/CLI11/pull/33), automatic on C++14
README.md
@@ -101,7 +101,7 @@ try { @@ -101,7 +101,7 @@ try {
101 } 101 }
102 ``` 102 ```
103 103
104 -> Note: The final five lines are so common, they have a dedicated macro: `CLI11_PARSE(app, argc, argv)`. You can use that as long as you don't need the return value of `.parse`. 104 +> Note: The final five lines are so common, they have a dedicated macro: `CLI11_PARSE(app, argc, argv)`.
105 105
106 106
107 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")`. 107 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")`.
@@ -176,11 +176,14 @@ On the command line, options can be given as: @@ -176,11 +176,14 @@ On the command line, options can be given as:
176 * `--file=filename` (equals) 176 * `--file=filename` (equals)
177 177
178 Extra positional arguments will cause the program to exit, so at least one positional option with a vector is recommended if you want to allow extraneous arguments. 178 Extra positional arguments will cause the program to exit, so at least one positional option with a vector is recommended if you want to allow extraneous arguments.
179 -If you set `.allow_extras()` on the main `App`, the parse function will return the left over arguments instead of throwing an error. You can access a vector of pointers to the parsed options in the original order using `parse_order()`. 179 +If you set `.allow_extras()` on the main `App`, you will not get an error. You can access the missing options using `remaining` (if you have subcommands, `app.remaining(true)` will get all remaining options, subcommands included).
  180 +
  181 +You can access a vector of pointers to the parsed options in the original order using `parse_order()`.
180 If `--` is present in the command line, 182 If `--` is present in the command line,
181 everything after that is positional only. 183 everything after that is positional only.
182 184
183 185
  186 +
184 ## Subcommands 187 ## Subcommands
185 188
186 Subcommands are supported, and can be nested infinitely. To add a subcommand, call the `add_subcommand` method with a name and an optional description. This gives a pointer to an `App` that behaves just like the main app, and can take options or further subcommands. Add `->ignore_case()` to a subcommand to allow any variation of caps to also be accepted. Children inherit the current setting from the parent. You cannot add multiple matching subcommand names at the same level (including ignore 189 Subcommands are supported, and can be nested infinitely. To add a subcommand, call the `add_subcommand` method with a name and an optional description. This gives a pointer to an `App` that behaves just like the main app, and can take options or further subcommands. Add `->ignore_case()` to a subcommand to allow any variation of caps to also be accepted. Children inherit the current setting from the parent. You cannot add multiple matching subcommand names at the same level (including ignore
@@ -205,8 +208,8 @@ There are several options that are supported on the main app and subcommands. Th @@ -205,8 +208,8 @@ There are several options that are supported on the main app and subcommands. Th
205 * `.get_subcommands()`: The list of subcommands given on the command line 208 * `.get_subcommands()`: The list of subcommands given on the command line
206 * `.parsed()`: True if this subcommand was given on the command line 209 * `.parsed()`: True if this subcommand was given on the command line
207 * `.set_callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point. 210 * `.set_callback(void() function)`: Set the callback that runs at the end of parsing. The options have already run at this point.
208 -* `.allow_extras()`: Do not throw an error if extra arguments are left over (Only useful on the main `App`, as that's the one that throws errors).  
209 -* `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognised item. It is ideal for allowing your app to be a "prefix" to calling another app. 211 +* `.allow_extras()`: Do not throw an error if extra arguments are left over
  212 +* `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognised item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app.
210 213
211 > Note: if you have a fixed number of required positional options, that will match before subcommand names. 214 > Note: if you have a fixed number of required positional options, that will match before subcommand names.
212 215
tests/SubcommandTest.cpp
@@ -345,14 +345,14 @@ TEST_F(TApp, PrefixProgram) { @@ -345,14 +345,14 @@ TEST_F(TApp, PrefixProgram) {
345 TEST_F(TApp, PrefixSubcom) { 345 TEST_F(TApp, PrefixSubcom) {
346 auto subc = app.add_subcommand("subc"); 346 auto subc = app.add_subcommand("subc");
347 subc->prefix_command(); 347 subc->prefix_command();
348 - 348 +
349 app.add_flag("--simple"); 349 app.add_flag("--simple");
350 - 350 +
351 args = {"--simple", "subc", "other", "--simple", "--mine"}; 351 args = {"--simple", "subc", "other", "--simple", "--mine"};
352 run(); 352 run();
353 -  
354 - EXPECT_EQ(app.remaining_size(), (size_t) 0);  
355 - EXPECT_EQ(app.remaining_size(true), (size_t) 3); 353 +
  354 + EXPECT_EQ(app.remaining_size(), (size_t)0);
  355 + EXPECT_EQ(app.remaining_size(true), (size_t)3);
356 EXPECT_EQ(subc->remaining(), std::vector<std::string>({"other", "--simple", "--mine"})); 356 EXPECT_EQ(subc->remaining(), std::vector<std::string>({"other", "--simple", "--mine"}));
357 } 357 }
358 358