Commit 6cfe98a5 authored by Paul's avatar Paul
Browse files

Improve error with incorrect order for command

parent 91523467
......@@ -377,6 +377,14 @@ struct argument_parser
};
}
template<class T>
void set_exe_name_to(T& x)
{
actions.push_back([&](auto& self) {
x = self.exe_name;
});
}
bool
run_action(const argument& arg, const std::string& flag, const std::vector<std::string>& inputs)
{
......@@ -441,6 +449,8 @@ struct argument_parser
}
}
}
for(auto&& action:actions)
action(*this);
return false;
}
......@@ -484,6 +494,7 @@ struct argument_parser
private:
std::list<argument> arguments;
std::string exe_name = "";
std::vector<std::function<void(argument_parser&)>> actions;
};
} // namespace MIGRAPHX_INLINE_NS
......
......@@ -570,7 +570,7 @@ struct main_command
{
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(wrong_commands, {}, ap.metavar("<command>"), ap.append());
ap(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help(get_command_help()));
ap(nullptr,
{"-v", "--version"},
......@@ -579,14 +579,32 @@ struct main_command
// Trim command off of exe name
ap.set_exe_name(ap.get_exe_name().substr(0, ap.get_exe_name().size() - 5));
ap.set_exe_name_to(exe_name);
}
bool unused = false;
std::vector<std::string> wrong_commands{};
std::string exe_name = "<exe>";
void run()
{
std::cout << color::fg_red << color::bold << "error: " << color::reset;
std::cout << get_command_help("missing command:") << std::endl;
auto it = std::find_if(wrong_commands.begin(), wrong_commands.end(), [](const auto& c) {
return get_commands().count(c) > 0;
});
if (it == wrong_commands.end())
{
std::cout << "'" << color::fg_yellow << wrong_commands.front() << color::reset << "' is not a valid command." << std::endl;
std::cout << get_command_help("Available commands:") << std::endl;
}
else
{
std::cout << "command '" << color::fg_yellow << *it << color::reset << "' must be first argument" << std::endl;
std::cout << std::endl;
std::cout << color::fg_yellow << "USAGE:" << color::reset << std::endl;
std::cout << " " << exe_name << " " << *it << " <options>" << std::endl;
}
std::cout << 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