Commit f0c57f28 authored by Paul's avatar Paul
Browse files

Shortedn call to add args

parent 90aca5c3
...@@ -62,7 +62,7 @@ struct argument_parser ...@@ -62,7 +62,7 @@ struct argument_parser
}; };
template <class T, class... Fs> template <class T, class... Fs>
void add(T& x, std::vector<std::string> flags, Fs... fs) void operator()(T& x, std::vector<std::string> flags, Fs... fs)
{ {
arguments.push_back({flags, [&](auto&&, const std::vector<std::string>& params) { arguments.push_back({flags, [&](auto&&, const std::vector<std::string>& params) {
if(params.empty()) if(params.empty())
...@@ -77,7 +77,7 @@ struct argument_parser ...@@ -77,7 +77,7 @@ struct argument_parser
} }
template <class... Fs> template <class... Fs>
void add(std::nullptr_t x, std::vector<std::string> flags, Fs... fs) void operator()(std::nullptr_t x, std::vector<std::string> flags, Fs... fs)
{ {
arguments.push_back({flags}); arguments.push_back({flags});
......
...@@ -32,7 +32,7 @@ void run_command(std::vector<std::string> args, bool add_help = false) ...@@ -32,7 +32,7 @@ void run_command(std::vector<std::string> args, bool add_help = false)
T x; T x;
argument_parser ap; argument_parser ap;
if(add_help) if(add_help)
ap.add(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help()); ap(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help());
x.parse(ap); x.parse(ap);
if(ap.parse(args)) if(ap.parse(args))
return; return;
......
...@@ -19,13 +19,13 @@ struct loader ...@@ -19,13 +19,13 @@ struct loader
void parse(argument_parser& ap) void parse(argument_parser& ap)
{ {
ap.add(file, {}, ap.metavar("<input file>")); ap(file, {}, ap.metavar("<input file>"));
ap.add(type, {"--onnx"}, ap.help("Load as onnx"), ap.set_value("onnx")); ap(type, {"--onnx"}, ap.help("Load as onnx"), ap.set_value("onnx"));
ap.add(type, {"--tf"}, ap.help("Load as tensorflow"), ap.set_value("tf")); ap(type, {"--tf"}, ap.help("Load as tensorflow"), ap.set_value("tf"));
ap.add(is_nhwc, {"--nhwc"}, ap.help("Treat tensorflow format as nhwc"), ap.set_value(true)); ap(is_nhwc, {"--nhwc"}, ap.help("Treat tensorflow format as nhwc"), ap.set_value(true));
ap.add( ap(
is_nhwc, {"--nchw"}, ap.help("Treat tensorflow format as nchw"), ap.set_value(false)); is_nhwc, {"--nchw"}, ap.help("Treat tensorflow format as nchw"), ap.set_value(false));
ap.add(trim, {"--trim", "-t"}, ap.help("Trim instructions from the end")); ap(trim, {"--trim", "-t"}, ap.help("Trim instructions from the end"));
} }
program load() program load()
...@@ -73,12 +73,12 @@ struct verify : command<verify> ...@@ -73,12 +73,12 @@ struct verify : command<verify>
void parse(argument_parser& ap) void parse(argument_parser& ap)
{ {
l.parse(ap); l.parse(ap);
ap.add(tolerance, {"--tolerance"}, ap.help("Tolerance for errors")); ap(tolerance, {"--tolerance"}, ap.help("Tolerance for errors"));
ap.add(per_instruction, ap(per_instruction,
{"-i", "--per-instruction"}, {"-i", "--per-instruction"},
ap.help("Verify each instruction"), ap.help("Verify each instruction"),
ap.set_value(true)); ap.set_value(true));
ap.add( ap(
reduce, {"-r", "--reduce"}, ap.help("Reduce program and verify"), ap.set_value(true)); reduce, {"-r", "--reduce"}, ap.help("Reduce program and verify"), ap.set_value(true));
} }
...@@ -113,7 +113,7 @@ struct main_command ...@@ -113,7 +113,7 @@ struct main_command
} }
void parse(argument_parser& ap) void parse(argument_parser& ap)
{ {
ap.add(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help(get_command_help())); ap(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help(get_command_help()));
} }
void run() {} void run() {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment