Restarted the production of the app

This commit is contained in:
Henry Winkel
2023-08-09 15:23:10 +02:00
parent b71f3b3bdf
commit 55ad5000dd
970 changed files with 453 additions and 79862 deletions

View File

@@ -0,0 +1 @@
add_cli_exe(subcommand_main subcommand_main.cpp subcommand_a.cpp subcommand_a.hpp)

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2017-2022, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
#include "subcommand_a.hpp"
#include <iostream>
#include <memory>
/// Set up a subcommand and capture a shared_ptr to a struct that holds all its options.
/// The variables of the struct are bound to the CLI options.
/// We use a shared ptr so that the addresses of the variables remain for binding,
/// You could return the shared pointer if you wanted to access the values in main.
void setup_subcommand_a(CLI::App &app) {
// Create the option and subcommand objects.
auto opt = std::make_shared<SubcommandAOptions>();
auto *sub = app.add_subcommand("subcommand_a", "performs subcommand a");
// Add options to sub, binding them to opt.
sub->add_option("-f,--file", opt->file, "File name")->required();
sub->add_flag("--with-foo", opt->with_foo, "Counter");
// Set the run function as callback to be called when this subcommand is issued.
sub->callback([opt]() { run_subcommand_a(*opt); });
}
/// The function that runs our code.
/// This could also simply be in the callback lambda itself,
/// but having a separate function is cleaner.
void run_subcommand_a(SubcommandAOptions const &opt) {
// Do stuff...
std::cout << "Working on file: " << opt.file << std::endl;
if(opt.with_foo) {
std::cout << "Using foo!" << std::endl;
}
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) 2017-2022, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <CLI/CLI.hpp>
#include <string>
/// Collection of all options of Subcommand A.
struct SubcommandAOptions {
std::string file;
bool with_foo;
};
// We could manually make a few variables and use shared pointers for each; this
// is just done this way to be nicely organized
// Function declarations.
void setup_subcommand_a(CLI::App &app);
void run_subcommand_a(SubcommandAOptions const &opt);

View File

@@ -0,0 +1,26 @@
// Copyright (c) 2017-2022, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
#include "subcommand_a.hpp"
#include <CLI/CLI.hpp>
int main(int argc, char **argv) {
CLI::App app{"..."};
// Call the setup functions for the subcommands.
// They are kept alive by a shared pointer in the
// lambda function held by CLI11
setup_subcommand_a(app);
// Make sure we get at least one subcommand
app.require_subcommand();
// More setup if needed, i.e., other subcommands etc.
CLI11_PARSE(app, argc, argv);
return 0;
}