blob: c3e21866f981571a035c7e6e1ac9f62e3f6a50b5 [file] [log] [blame]
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05001#include "handler.hpp"
2
3#include <CLI/CLI.hpp>
4
5int main(int argc, char** argv)
6{
7
8 CLI::App app{"PLDM requester tool for OpenBMC"};
9
10 // TODO: To enable it later
11 // bool verbose_flag = false;
12 // app.add_flag("-v, --verbose", verbose_flag, "Output debug logs ");
13 std::vector<std::string> args{};
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050014 app.add_option("-c, —command", args, " PLDM request command");
15
16 std::string rawCmd;
17 app.add_option("raw", rawCmd, "Send a RAW PLDM request and print response");
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050018
19 std::string pldmCmdName;
20 app.add_option("GetPLDMTypes", pldmCmdName, "Get PLDM Type");
21 app.add_option("GetPLDMVersion", pldmCmdName, "Get PLDM Version");
22
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050023 app.add_subcommand("BASE", "PLDM Command Type = BASE");
24 app.add_subcommand("BIOS", "PLDM Command Type = BIOS");
25 app.add_subcommand("OEM", "PLDM Command Type = OEM");
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050026
27 CLI11_PARSE(app, argc, argv);
28
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050029 std::string cmdName;
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050030 int rc = 0;
31
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050032 if (args[0] != "raw")
33 {
34 // Parse args to program
35 cmdName = args[0];
36 }
37 else
38 {
39 // removing 'raw' from the args list since it is positional argument
40 // and not an input value.
41 args.erase(args.begin());
42
43 // loop through the remaining argument list
44 for (auto&& item : args)
45 {
46
47 if (item[0] == '0' && (item[1] == 'x' || item[1] == 'X'))
48 {
49
50 // Erase 0x from input
51 item.erase(0, 2);
52
53 // Check for hex input value validity
54 if (std::all_of(item.begin(), item.end(), ::isxdigit))
55 {
56
57 // Parse args to program
58 cmdName = "HandleRawOp";
59 }
60 else
61 {
62 std::cerr << item << " contains non hex digits. Re-enter"
63 << std::endl;
64 rc = -1;
65 return rc;
66 }
67 }
68 else
69 {
70 std::cout << item << " Input hex value starting with 0x "
71 << std::endl;
72 rc = -1;
73 return rc;
74 }
75 }
76 }
77
78 Handler handler;
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050079 try
80 {
81 handler.dispatcher.at(cmdName)(std::move(args));
82 }
83 catch (const std::out_of_range& e)
84 {
85 std::cerr << cmdName << " is not supported!" << std::endl;
86 rc = -1;
87 }
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050088 return rc;
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050089}