Name change & Added custom usage when using -h
This commit is contained in:
parent
120aa49529
commit
f73357ee9d
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
project(discord-timestamp)
|
||||
project(distime)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME}
|
||||
|
|
|
|||
38
src/main.cpp
38
src/main.cpp
|
|
@ -1,34 +1,26 @@
|
|||
#include <iostream>
|
||||
#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) {
|
||||
// Set up a command-line app with a description
|
||||
CLI::App app{"This app demonstrates explicit usage printing with CLI11"};
|
||||
CLI::App app{};
|
||||
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
|
||||
int value{0};
|
||||
app.add_option("-v,--value", value, "An integer value to process")
|
||||
->default_val("0"); // Add a default value
|
||||
// Define options
|
||||
int p = 0;
|
||||
app.add_option("-p", p, "Parameter");
|
||||
|
||||
// Add a positional argument
|
||||
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";
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
std::cout << "Parameter value: " << p << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user