Playing around further with CLI11
This commit is contained in:
parent
f87f628082
commit
120aa49529
28
src/main.cpp
28
src/main.cpp
|
|
@ -1,18 +1,34 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "CLI11.hpp"
|
#include "CLI11.hpp"
|
||||||
|
|
||||||
int main([[maybe_unused]] int argc,[[maybe_unused]] char **argv) {
|
|
||||||
CLI::App app{"Test program thus far"};
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
// Set up a command-line app with a description
|
||||||
|
CLI::App app{"This app demonstrates explicit usage printing with CLI11"};
|
||||||
|
|
||||||
|
// Add a flag
|
||||||
bool test{false};
|
bool test{false};
|
||||||
app.add_flag("-f", test, "Test flag");
|
app.add_flag("-f,--flag", test, "A test flag");
|
||||||
|
|
||||||
|
// Add an option
|
||||||
|
int value{0};
|
||||||
|
app.add_option("-v,--value", value, "An integer value to process")
|
||||||
|
->default_val("0"); // Add a default value
|
||||||
|
|
||||||
|
// Add a positional argument
|
||||||
|
std::string input;
|
||||||
|
app.add_option("usage", input, "THIS IS A TEST")->group("Usage");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
app.parse(argc, argv);
|
app.parse(argc, argv);
|
||||||
} catch(const CLI::ParseError &e) {
|
} catch (const CLI::ParseError &e) {
|
||||||
return app.exit(e);
|
return app.exit(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test)
|
// Print the parsed arguments for demonstration
|
||||||
std::cout << "Hello world";
|
std::cout << "Flag value: " << (test ? "true" : "false") << "\n";
|
||||||
|
std::cout << "Integer value: " << value << "\n";
|
||||||
|
std::cout << "Input file: " << input << "\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user