-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
40 lines (32 loc) · 1.18 KB
/
example.cpp
File metadata and controls
40 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include "Arg.hpp"
#include "Parser.hpp"
#include "utils.hpp"
void run(ClapParser& arg_parser);
int main(const int argc, char* argv[]) {
ClapParser arg_parser;
auto num1 = Arg("num1").from_env("ASDF").auto_env().required(true);
// std::cerr << num1 << "\n";
arg_parser.add_arg(num1);
auto num2 = Arg("num2").short_name("N").from_env("TES").default_value("99");
arg_parser.add_arg(num2);
arg_parser.add_arg(Arg("test").is_flag());
// arg_parser.add_arg(Arg("test").is_flag(true));
try {
arg_parser.parse(argc, argv);
// std::cerr << arg_parser;
run(arg_parser);
} catch (const std::exception& e) {
std::cerr << "\n\n\nerror: " << e.what() << "\n\n\n";
// arg_parser.print_help();
}
}
void run(ClapParser& arg_parser) {
// std::cerr << "running\n";
auto num1 = ok_or_throw_str(arg_parser.get_one_as<int>("num1"), "num1 not defined");
auto num2 = ok_or_throw_str(arg_parser.get_one_as<double>("num2"), "num2 not defined");
std::cout << "num1: " << num1 << '\n';
std::cout.precision(5);
std::cout << std::fixed << "num2: " << num2 << '\n';
// std::cerr << arg_parser;
}