1#include "argman.hpp"
2
3#include <iostream>
4
5using namespace ArgMan;
6
7class BuildCommand : public Command {
8public:
9 BuildCommand(const string &name, const string &description)
10 : Command(name, description) {}
11
12 void execute() override {
13 auto debug_option = get_option<bool>("debug");
14 auto ldflags_option = get_option<string>("ldflags");
15
16 cout << "Debug: " << (debug_option->value ? "true" : "false") << endl;
17 cout << "LDFLAGS: " << ldflags_option->value << endl;
18 }
19};
20
21int main(int argc, char *argv[]) {
22 auto command_line_parser = make_shared<CommandLineParser>("argman");
23
24 auto build_command = make_unique<BuildCommand>("build", "Build the project");
25 build_command->add_option(
26 make_unique<Option<string>>("ldflags", "Linker flags", ""));
27 build_command->add_option(
28 make_unique<Option<bool>>("debug", "Debug mode", false));
29
30 command_line_parser->add_command(std::move(build_command));
31
32 try {
33 command_line_parser->parse(argc, argv);
34 } catch (const exception &e) {
35 cerr << command_line_parser->app_name << ": error: " << e.what() << endl;
36 return 1;
37 }
38
39 return 0;
40}