John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 1 | #include "pldm_base_cmd.hpp" |
| 2 | #include "pldm_cmd_helper.hpp" |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 3 | |
| 4 | #include <CLI/CLI.hpp> |
| 5 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 6 | namespace pldmtool |
| 7 | { |
| 8 | |
| 9 | namespace raw |
| 10 | { |
| 11 | |
| 12 | using namespace pldmtool::helper; |
| 13 | |
| 14 | namespace |
| 15 | { |
| 16 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 17 | } |
| 18 | |
| 19 | class 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 | |
| 51 | void 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. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 61 | int main(int argc, char** argv) |
| 62 | { |
| 63 | |
| 64 | CLI::App app{"PLDM requester tool for OpenBMC"}; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 65 | app.require_subcommand(1)->ignore_case(); |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 66 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 67 | pldmtool::raw::registerCommand(app); |
| 68 | pldmtool::base::registerCommand(app); |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 69 | |
| 70 | CLI11_PARSE(app, argc, argv); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 71 | return 0; |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 72 | } |