Playing around further with CLI11
This commit is contained in:
parent
f87f628082
commit
120aa49529
26
src/main.cpp
26
src/main.cpp
|
|
@ -1,11 +1,23 @@
|
|||
#include <iostream>
|
||||
#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};
|
||||
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 {
|
||||
app.parse(argc, argv);
|
||||
|
|
@ -13,6 +25,10 @@ int main([[maybe_unused]] int argc,[[maybe_unused]] char **argv) {
|
|||
return app.exit(e);
|
||||
}
|
||||
|
||||
if (test)
|
||||
std::cout << "Hello world";
|
||||
// Print the parsed arguments for demonstration
|
||||
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