-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_set_opts.cpp
43 lines (35 loc) · 1.88 KB
/
pipeline_set_opts.cpp
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
41
42
43
#include <iostream>
#include "simple-args-parser.hpp"
template <typename T>
void GetAndPrintValue(const args::Parser &parser, const std::string &name)
{
auto val = parser.GetOptValue<T>(name);
if (val)
{
std::cout << "Option (" << name << ") - value: " << *val << std::endl;
}
else
{
std::cout << "No option (" << name << ")" << std::endl;
}
}
int main(int argc, char **argv)
{
args::Parser args_parser(args::ParserMode::IGNORE_UNKNOWN_ARGUMENTS);
args_parser.SetOpt<int> ({"-i" , "--int" , "--integer" }, args::ArgType::ARGS_REQUIRED, "Int description" )
.SetOpt<long> ({"-l" , "--long" }, args::ArgType::ARGS_REQUIRED, "Long description" )
.SetOpt<unsigned int> ({"-ui", "--uint" , "--unsignedinteger"}, args::ArgType::ARGS_REQUIRED, "Unsigned int description" )
.SetOpt<unsigned long>({"-ul", "--ulong" , "--unsignedlong" }, args::ArgType::ARGS_REQUIRED, "Unsigned long description")
.SetOpt<double> ({"-d" , "--double" }, args::ArgType::ARGS_REQUIRED, "Double description" )
.SetOpt<float> ({"-f" , "--float" }, args::ArgType::ARGS_REQUIRED, "Float description" )
.SetOpt<std::string> ({"-s" , "--string" }, args::ArgType::ARGS_REQUIRED, "String description" );
args_parser.Parse(argc, argv);
GetAndPrintValue<int> (args_parser, "-i");
GetAndPrintValue<long> (args_parser, "-l");
GetAndPrintValue<unsigned int> (args_parser, "-ui");
GetAndPrintValue<unsigned long>(args_parser, "-ul");
GetAndPrintValue<double> (args_parser, "-d");
GetAndPrintValue<float> (args_parser, "-f");
GetAndPrintValue<std::string> (args_parser, "-s");
return 0;
}