Commit 8cdf1c865139ed08b25c6939779920b422b466b1
Committed by
Henry Schreiner
1 parent
6d26440b
Style updates
Showing
4 changed files
with
15 additions
and
18 deletions
examples/subcom_in_files/main.cpp
| ... | ... | @@ -4,13 +4,13 @@ |
| 4 | 4 | |
| 5 | 5 | #include "subcommand_a.hpp" |
| 6 | 6 | |
| 7 | -int main( int argc, char** argv ) { | |
| 7 | +int main(int argc, char **argv) { | |
| 8 | 8 | CLI::App app{"..."}; |
| 9 | 9 | |
| 10 | 10 | // Call the setup functions for the subcommands. |
| 11 | - // They are kept alive by a shared pointer in the | |
| 11 | + // They are kept alive by a shared pointer in the | |
| 12 | 12 | // lambda function held by CLI11 |
| 13 | - setup_subcommand_a( app ); | |
| 13 | + setup_subcommand_a(app); | |
| 14 | 14 | |
| 15 | 15 | // Make sure we get at least one subcommand |
| 16 | 16 | app.require_subcommand(); | ... | ... |
examples/subcom_in_files/subcommand_a.cpp
| ... | ... | @@ -8,20 +8,18 @@ |
| 8 | 8 | /// The variables of the struct are bound to the CLI options. |
| 9 | 9 | /// We use a shared ptr so that the addresses of the variables remain for binding, |
| 10 | 10 | /// You could return the shared pointer if you wanted to access the values in main. |
| 11 | -void setup_subcommand_a( CLI::App& app ) { | |
| 11 | +void setup_subcommand_a(CLI::App &app) { | |
| 12 | 12 | // Create the option and subcommand objects. |
| 13 | 13 | auto opt = std::make_shared<SubcommandAOptions>(); |
| 14 | - auto sub = app.add_subcommand( "subcommand_a", "performs subcommand a", true ); | |
| 14 | + auto sub = app.add_subcommand("subcommand_a", "performs subcommand a", true); | |
| 15 | 15 | |
| 16 | 16 | // Add options to sub, binding them to opt. |
| 17 | 17 | sub->add_option("-f,--file", opt->file, "File name")->required(); |
| 18 | 18 | sub->add_flag("--with-foo", opt->with_foo, "Counter"); |
| 19 | 19 | |
| 20 | 20 | // Set the run function as callback to be called when this subcommand is issued. |
| 21 | - sub->set_callback([opt]() { | |
| 22 | - run_subcommand_a( *opt ); | |
| 23 | - }); | |
| 24 | - | |
| 21 | + sub->set_callback([opt]() { run_subcommand_a(*opt); }); | |
| 22 | + | |
| 25 | 23 | // Note: In C++14, you could make a unique pointer, then pass it into the lambda function via |
| 26 | 24 | // a move. That's slightly more elegant, but you won't be able to see the runtime difference |
| 27 | 25 | // in skipping one mutex check for shared_ptr. |
| ... | ... | @@ -30,11 +28,10 @@ void setup_subcommand_a( CLI::App& app ) { |
| 30 | 28 | /// The function that runs our code. |
| 31 | 29 | /// This could also simply be in the callback lambda itself, |
| 32 | 30 | /// but having a separate function is cleaner. |
| 33 | -void run_subcommand_a( SubcommandAOptions const& opt ) | |
| 34 | -{ | |
| 31 | +void run_subcommand_a(SubcommandAOptions const &opt) { | |
| 35 | 32 | // Do stuff... |
| 36 | 33 | std::cout << "Working on file: " << opt.file << std::endl; |
| 37 | - if( opt.with_foo ) { | |
| 34 | + if(opt.with_foo) { | |
| 38 | 35 | std::cout << "Using foo!" << std::endl; |
| 39 | 36 | } |
| 40 | 37 | } | ... | ... |
examples/subcom_in_files/subcommand_a.hpp
| ... | ... | @@ -9,12 +9,12 @@ |
| 9 | 9 | /// Collection of all options of Subcommand A. |
| 10 | 10 | struct SubcommandAOptions { |
| 11 | 11 | std::string file; |
| 12 | - bool with_foo; | |
| 12 | + bool with_foo; | |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | 15 | // We could manually make a few variables and use shared pointers for each; this |
| 16 | -// is just done this way to be nicely organized | |
| 16 | +// is just done this way to be nicely organized | |
| 17 | 17 | |
| 18 | 18 | // Function declarations. |
| 19 | -void setup_subcommand_a( CLI::App& app ); | |
| 20 | -void run_subcommand_a( SubcommandAOptions const& opt ); | |
| 19 | +void setup_subcommand_a(CLI::App &app); | |
| 20 | +void run_subcommand_a(SubcommandAOptions const &opt); | ... | ... |
include/CLI/App.hpp
| ... | ... | @@ -45,8 +45,8 @@ using App_p = std::unique_ptr<App>; |
| 45 | 45 | |
| 46 | 46 | /// Creates a command line program, with very few defaults. |
| 47 | 47 | /** To use, create a new `Program()` instance with `argc`, `argv`, and a help description. The templated |
| 48 | -* add_option methods make it easy to prepare options. Remember to call `.start` before starting your | |
| 49 | -* program, so that the options can be evaluated and the help option doesn't accidentally run your program. */ | |
| 48 | + * add_option methods make it easy to prepare options. Remember to call `.start` before starting your | |
| 49 | + * program, so that the options can be evaluated and the help option doesn't accidentally run your program. */ | |
| 50 | 50 | class App { |
| 51 | 51 | friend Option; |
| 52 | 52 | friend detail::AppFriend; | ... | ... |