PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 1 | #include "vpd_tool_impl.hpp" |
| 2 | |
| 3 | #include <CLI/CLI.hpp> |
| 4 | #include <fstream> |
| 5 | #include <iostream> |
| 6 | |
| 7 | using namespace CLI; |
| 8 | using namespace std; |
| 9 | |
| 10 | int main(int argc, char** argv) |
| 11 | { |
| 12 | App app{"VPD Command line tool to dump the inventory and to read and " |
| 13 | "update the keywords"}; |
| 14 | |
| 15 | string objectPath{}; |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 16 | string recordName{}; |
| 17 | string keyword{}; |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 18 | |
| 19 | auto object = |
| 20 | app.add_option("--object, -O", objectPath, "Enter the Object Path"); |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 21 | auto record = |
| 22 | app.add_option("--record, -R", recordName, "Enter the Record Name"); |
| 23 | auto kw = app.add_option("--keyword, -K", keyword, "Enter the Keyword"); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 24 | |
| 25 | auto dumpObjFlag = |
| 26 | app.add_flag("--dumpObject, -o", |
| 27 | "Dump the given object from the inventory. { " |
| 28 | "vpd-tool-exe --dumpObject/-o --object/-O object-name }") |
| 29 | ->needs(object); |
| 30 | |
| 31 | auto dumpInvFlag = app.add_flag( |
| 32 | "--dumpInventory, -i", "Dump all the inventory objects. { vpd-tool-exe " |
| 33 | "--dumpInventory/-i }"); |
| 34 | |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 35 | auto readFlag = |
| 36 | app.add_flag("--readKeyword, -r", |
| 37 | "Read the data of the given keyword. { " |
| 38 | "vpd-tool-exe --readKeyword/-r --object/-O " |
| 39 | "\"object-name\" --record/-R \"record-name\" --keyword/-K " |
| 40 | "\"keyword-name\" }") |
| 41 | ->needs(object) |
| 42 | ->needs(record) |
| 43 | ->needs(kw); |
| 44 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 45 | CLI11_PARSE(app, argc, argv); |
| 46 | |
| 47 | ifstream inventoryJson(INVENTORY_JSON); |
| 48 | auto jsObject = json::parse(inventoryJson); |
| 49 | |
| 50 | try |
| 51 | { |
| 52 | if (*dumpObjFlag) |
| 53 | { |
| 54 | VpdTool vpdToolObj(move(objectPath)); |
| 55 | vpdToolObj.dumpObject(jsObject); |
| 56 | } |
| 57 | |
| 58 | else if (*dumpInvFlag) |
| 59 | { |
| 60 | VpdTool vpdToolObj; |
| 61 | vpdToolObj.dumpInventory(jsObject); |
| 62 | } |
| 63 | |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 64 | else if (*readFlag) |
| 65 | { |
| 66 | VpdTool vpdToolObj(move(objectPath), move(recordName), |
| 67 | move(keyword)); |
| 68 | vpdToolObj.readKeyword(); |
| 69 | } |
| 70 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 71 | else |
| 72 | { |
| 73 | throw runtime_error("One of the valid options is required. Refer " |
| 74 | "--help for list of options."); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | catch (exception& e) |
| 79 | { |
| 80 | cerr << e.what(); |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |