-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.cpp
More file actions
25 lines (24 loc) · 1.19 KB
/
simple.cpp
File metadata and controls
25 lines (24 loc) · 1.19 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
#include "cliargs.hpp"
int main(int argc, char *argv[]) {
// Create a 'cliargs::Parser' instance
cliargs::Parser parser("MyProgram", "One line description of MyProgram");
// Define arguments
parser.set_width(120).add_args()
('h', "help", "Print this message and exit") // a bool argument
('i', "int", "An interger", cliargs::value<int>()->default_value(-1))
('s', "string", "A string", cliargs::value<std::string>()->default_value("/dev/mem"), "str")
('v', "vector", "An int vector", cliargs::value<std::vector<float>>()->data_count(1, 2))
;
// Parse
auto result = parser.parse(argc, argv);
if (parser.error() || result["help"].as<bool>()) {
parser.print_help();
return parser.error() ? -1 : 0;
}
// Use result
std::cout << " int: " << cliargs::to_string(result["int"].as<int>()) << std::endl;
std::cout << "string: " << cliargs::to_string(result["string"].as<std::string>()) << std::endl;
std::cout << "vector: " << cliargs::to_string(result["vector"].as<std::vector<float>>()) << std::endl;
std::cout << " tail: " << cliargs::to_string(result.tail().argv, result.tail().argc) << std::endl;
return 0;
}