Name change & Added custom usage when using -h

This commit is contained in:
theskywinds 2025-06-20 15:35:42 +02:00
parent 120aa49529
commit f73357ee9d
2 changed files with 16 additions and 24 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(discord-timestamp) project(distime)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
add_executable(${CMAKE_PROJECT_NAME} add_executable(${CMAKE_PROJECT_NAME}

View File

@ -1,34 +1,26 @@
#include <iostream> #include <iostream>
#include "CLI11.hpp" #include "CLI11.hpp"
class MyFormatter : public CLI::Formatter {
public:
MyFormatter() : Formatter() {}
std::string make_usage([[maybe_unused]] const CLI::App *app, [[maybe_unused]] std::string name) const override {
return "USAGE: " + name + " [OPTIONS]";
};
};
int main(int argc, char **argv) { int main(int argc, char **argv) {
// Set up a command-line app with a description CLI::App app{};
CLI::App app{"This app demonstrates explicit usage printing with CLI11"}; auto fmt = std::make_shared<MyFormatter>();
app.formatter(fmt);
// Add a flag
bool test{false};
app.add_flag("-f,--flag", test, "A test flag");
// Add an option // Define options
int value{0}; int p = 0;
app.add_option("-v,--value", value, "An integer value to process") app.add_option("-p", p, "Parameter");
->default_val("0"); // Add a default value
// Add a positional argument CLI11_PARSE(app, argc, argv);
std::string input;
app.add_option("usage", input, "THIS IS A TEST")->group("Usage");
try {
app.parse(argc, argv);
} catch (const CLI::ParseError &e) {
return app.exit(e);
}
// 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";
std::cout << "Parameter value: " << p << std::endl;
return 0; return 0;
} }