Commit 91523467 authored by Paul's avatar Paul
Browse files

Format

parent c4bba3cf
......@@ -257,11 +257,11 @@ struct argument_parser
});
}
template<class F>
template <class F>
argument* find_argument(F f)
{
auto it = std::find_if(arguments.begin(), arguments.end(), f);
if (it == arguments.end())
if(it == arguments.end())
return nullptr;
return std::addressof(*it);
}
......@@ -269,14 +269,15 @@ struct argument_parser
MIGRAPHX_DRIVER_STATIC auto show_help(const std::string& msg = "")
{
return do_action([=](auto& self) {
argument* input_argument = self.find_argument([](const auto& arg) { return arg.flags.empty(); });
argument* input_argument =
self.find_argument([](const auto& arg) { return arg.flags.empty(); });
std::cout << color::fg_yellow << "USAGE:" << color::reset << std::endl;
std::cout << " " << self.exe_name << " <options> ";
if (input_argument)
if(input_argument)
std::cout << input_argument->metavar;
std::cout << std::endl;
std::cout << std::endl;
if (self.find_argument([](const auto& arg) { return arg.nargs == 0; }))
if(self.find_argument([](const auto& arg) { return arg.nargs == 0; }))
{
std::cout << color::fg_yellow << "FLAGS:" << color::reset << std::endl;
std::cout << std::endl;
......@@ -310,7 +311,7 @@ struct argument_parser
}
std::cout << std::endl;
}
if (self.find_argument([](const auto& arg) { return arg.nargs != 0; }))
if(self.find_argument([](const auto& arg) { return arg.nargs != 0; }))
{
std::cout << color::fg_yellow << "OPTIONS:" << color::reset << std::endl;
for(auto&& arg : self.arguments)
......@@ -376,7 +377,8 @@ struct argument_parser
};
}
bool run_action(const argument& arg, const std::string& flag, const std::vector<std::string>& inputs)
bool
run_action(const argument& arg, const std::string& flag, const std::vector<std::string>& inputs)
{
std::string msg = "";
try
......@@ -406,10 +408,11 @@ struct argument_parser
std::cout << " " << exe_name << " ";
show_usage();
std::cout << std::endl;
if (find_argument([](const auto& a) { return contains(a.flags, "--help"); }))
if(find_argument([](const auto& a) { return contains(a.flags, "--help"); }))
{
std::cout << std::endl;
std::cout << "For more information try '" << color::fg_green << "--help" << color::reset << "'" << std::endl;
std::cout << "For more information try '" << color::fg_green << "--help" << color::reset
<< "'" << std::endl;
}
return true;
}
......@@ -441,15 +444,9 @@ struct argument_parser
return false;
}
void set_exe_name(const std::string& s)
{
exe_name = s;
}
void set_exe_name(const std::string& s) { exe_name = s; }
const std::string& get_exe_name() const
{
return exe_name;
}
const std::string& get_exe_name() const { return exe_name; }
using string_map = std::unordered_map<std::string, std::vector<std::string>>;
template <class IsKeyword>
......
......@@ -18,7 +18,10 @@ inline namespace MIGRAPHX_INLINE_NS {
inline auto& get_commands()
{
// NOLINTNEXTLINE
static std::unordered_map<std::string, std::function<void(const std::string& exe_name, std::vector<std::string> args)>> m;
static std::unordered_map<
std::string,
std::function<void(const std::string& exe_name, std::vector<std::string> args)>>
m;
return m;
}
......@@ -59,7 +62,9 @@ template <class T>
int auto_register_command()
{
auto& m = get_commands();
m[command_name<T>()] = [](const std::string& exe_name, std::vector<std::string> args) { run_command<T>(exe_name, args, true); };
m[command_name<T>()] = [](const std::string& exe_name, std::vector<std::string> args) {
run_command<T>(exe_name, args, true);
};
return 0;
}
......
......@@ -552,24 +552,25 @@ struct onnx : command<onnx>
struct main_command
{
static std::string get_command_help(const std::string& title = colorize(color::fg_yellow, "COMMANDS:"))
static std::string get_command_help(const std::string& title = colorize(color::fg_yellow,
"COMMANDS:"))
{
std::string result = title + "\n";
std::vector<std::string> commands(get_commands().size());
std::transform(get_commands().begin(), get_commands().end(), commands.begin(), [](const auto& p) {
return colorize(color::fg_green, p.first);
});
std::transform(get_commands().begin(),
get_commands().end(),
commands.begin(),
[](const auto& p) { return colorize(color::fg_green, p.first); });
std::sort(commands.begin(), commands.end());
return std::accumulate(commands.begin(),
commands.end(),
result,
[](auto r, auto&& s) { return r + " " + s + "\n"; });
return std::accumulate(commands.begin(), commands.end(), result, [](auto r, auto&& s) {
return r + " " + s + "\n";
});
}
void parse(argument_parser& ap)
{
std::string version_str = "MIGraphX Version: " + std::to_string(MIGRAPHX_VERSION_MAJOR) +
"." + std::to_string(MIGRAPHX_VERSION_MINOR);
ap(unused, {}, ap.metavar("<command>"), ap.set_value(true));
ap(unused, {}, ap.metavar("<command>"), ap.set_value(true));
ap(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help(get_command_help()));
ap(nullptr,
{"-v", "--version"},
......@@ -583,9 +584,9 @@ struct main_command
bool unused = false;
void run()
{
{
std::cout << color::fg_red << color::bold << "error: " << color::reset;
std::cout << get_command_help("missing command:") << std::endl;
std::cout << get_command_help("missing command:") << std::endl;
}
};
......
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