blob: 7244e4708d1056cf81446633116075772e51c76e [file] [log] [blame]
John Wang58a0e062019-11-08 15:38:15 +08001#include "pldm_base_cmd.hpp"
2#include "pldm_cmd_helper.hpp"
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05003
4#include <CLI/CLI.hpp>
5
John Wang58a0e062019-11-08 15:38:15 +08006namespace pldmtool
7{
8
9namespace raw
10{
11
12using namespace pldmtool::helper;
13
14namespace
15{
16std::vector<std::unique_ptr<CommandInterface>> commands;
17}
18
19class RawOp : public CommandInterface
20{
21 public:
22 ~RawOp() = default;
23 RawOp() = delete;
24 RawOp(const RawOp&) = delete;
25 RawOp(RawOp&&) = default;
26 RawOp& operator=(const RawOp&) = delete;
27 RawOp& operator=(RawOp&&) = default;
28
29 explicit RawOp(const char* type, const char* name, CLI::App* app) :
30 CommandInterface(type, name, app)
31 {
32 app->add_option("-d,--data", rawData, "raw data")
33 ->required()
34 ->expected(-3);
35 }
36 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
37
38 {
39 return {PLDM_SUCCESS, rawData};
40 }
41
42 void parseResponseMsg(pldm_msg* /* responsePtr */,
43 size_t /* payloadLength */) override
44 {
45 }
46
47 private:
48 std::vector<uint8_t> rawData;
49};
50
51void registerCommand(CLI::App& app)
52{
53 auto raw =
54 app.add_subcommand("raw", "send a raw request and print response");
55 commands.push_back(std::make_unique<RawOp>("raw", "raw", raw));
56}
57
58} // namespace raw
59} // namespace pldmtool
60
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050061int main(int argc, char** argv)
62{
63
64 CLI::App app{"PLDM requester tool for OpenBMC"};
John Wang58a0e062019-11-08 15:38:15 +080065 app.require_subcommand(1)->ignore_case();
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050066
John Wang58a0e062019-11-08 15:38:15 +080067 pldmtool::raw::registerCommand(app);
68 pldmtool::base::registerCommand(app);
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050069
70 CLI11_PARSE(app, argc, argv);
John Wang58a0e062019-11-08 15:38:15 +080071 return 0;
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050072}