John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 1 | #include "pldm_base_cmd.hpp" |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 2 | #include "pldm_bios_cmd.hpp" |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 3 | #include "pldm_cmd_helper.hpp" |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 4 | |
| 5 | #include <CLI/CLI.hpp> |
| 6 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 7 | namespace pldmtool |
| 8 | { |
| 9 | |
| 10 | namespace raw |
| 11 | { |
| 12 | |
| 13 | using namespace pldmtool::helper; |
| 14 | |
| 15 | namespace |
| 16 | { |
| 17 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 18 | } |
| 19 | |
| 20 | class RawOp : public CommandInterface |
| 21 | { |
| 22 | public: |
| 23 | ~RawOp() = default; |
| 24 | RawOp() = delete; |
| 25 | RawOp(const RawOp&) = delete; |
| 26 | RawOp(RawOp&&) = default; |
| 27 | RawOp& operator=(const RawOp&) = delete; |
| 28 | RawOp& operator=(RawOp&&) = default; |
| 29 | |
| 30 | explicit RawOp(const char* type, const char* name, CLI::App* app) : |
| 31 | CommandInterface(type, name, app) |
| 32 | { |
| 33 | app->add_option("-d,--data", rawData, "raw data") |
| 34 | ->required() |
| 35 | ->expected(-3); |
| 36 | } |
| 37 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 38 | |
| 39 | { |
| 40 | return {PLDM_SUCCESS, rawData}; |
| 41 | } |
| 42 | |
| 43 | void parseResponseMsg(pldm_msg* /* responsePtr */, |
| 44 | size_t /* payloadLength */) override |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | std::vector<uint8_t> rawData; |
| 50 | }; |
| 51 | |
| 52 | void registerCommand(CLI::App& app) |
| 53 | { |
| 54 | auto raw = |
| 55 | app.add_subcommand("raw", "send a raw request and print response"); |
| 56 | commands.push_back(std::make_unique<RawOp>("raw", "raw", raw)); |
| 57 | } |
| 58 | |
| 59 | } // namespace raw |
| 60 | } // namespace pldmtool |
| 61 | |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 62 | int main(int argc, char** argv) |
| 63 | { |
| 64 | |
| 65 | CLI::App app{"PLDM requester tool for OpenBMC"}; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 66 | app.require_subcommand(1)->ignore_case(); |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 67 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 68 | pldmtool::raw::registerCommand(app); |
| 69 | pldmtool::base::registerCommand(app); |
Sridevi Ramesh | 9857643 | 2019-11-27 10:10:28 -0600 | [diff] [blame] | 70 | pldmtool::bios::registerCommand(app); |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 71 | |
| 72 | CLI11_PARSE(app, argc, argv); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 73 | return 0; |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 74 | } |