main.cpp 971 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
8
#include "argument_parser.hpp"
#include "command.hpp"

struct main_command
{
    static std::string get_command_help()
    {
        std::string result = "Commands:\n";
Paul's avatar
Paul committed
9
        for(const auto& p : migraphx::driver::get_commands())
Paul's avatar
Paul committed
10
11
12
13
14
15
16
17
18
19
20
            result += "    " + p.first + "\n";
        return result;
    }
    void parse(migraphx::driver::argument_parser& ap)
    {
        ap.add(nullptr, {"-h", "--help"}, ap.help("Show help"), ap.show_help(get_command_help()));
    }

    void run() {}
};

Paul's avatar
Paul committed
21
22
int main(int argc, const char* argv[])
{
Paul's avatar
Paul committed
23
    std::vector<std::string> args(argv + 1, argv + argc);
Paul's avatar
Paul committed
24
    if(args.empty())
Paul's avatar
Paul committed
25
26
27
        return 0;
    auto&& m = migraphx::driver::get_commands();
    auto cmd = args.front();
Paul's avatar
Paul committed
28
    if(m.count(cmd) > 0)
Paul's avatar
Paul committed
29
    {
Paul's avatar
Paul committed
30
        m.at(cmd)({args.begin() + 1, args.end()});
Paul's avatar
Paul committed
31
    }
Paul's avatar
Paul committed
32
    else
Paul's avatar
Paul committed
33
34
35
36
37
    {
        migraphx::driver::argument_parser ap;
        main_command mc;
        mc.parse(ap);
        ap.parse(args);
Paul's avatar
Paul committed
38
        mc.run();
Paul's avatar
Paul committed
39
40
41
    }
    return 0;
}