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{}; |
| 16 | |
| 17 | auto object = |
| 18 | app.add_option("--object, -O", objectPath, "Enter the Object Path"); |
| 19 | |
| 20 | auto dumpObjFlag = |
| 21 | app.add_flag("--dumpObject, -o", |
| 22 | "Dump the given object from the inventory. { " |
| 23 | "vpd-tool-exe --dumpObject/-o --object/-O object-name }") |
| 24 | ->needs(object); |
| 25 | |
| 26 | auto dumpInvFlag = app.add_flag( |
| 27 | "--dumpInventory, -i", "Dump all the inventory objects. { vpd-tool-exe " |
| 28 | "--dumpInventory/-i }"); |
| 29 | |
| 30 | CLI11_PARSE(app, argc, argv); |
| 31 | |
| 32 | ifstream inventoryJson(INVENTORY_JSON); |
| 33 | auto jsObject = json::parse(inventoryJson); |
| 34 | |
| 35 | try |
| 36 | { |
| 37 | if (*dumpObjFlag) |
| 38 | { |
| 39 | VpdTool vpdToolObj(move(objectPath)); |
| 40 | vpdToolObj.dumpObject(jsObject); |
| 41 | } |
| 42 | |
| 43 | else if (*dumpInvFlag) |
| 44 | { |
| 45 | VpdTool vpdToolObj; |
| 46 | vpdToolObj.dumpInventory(jsObject); |
| 47 | } |
| 48 | |
| 49 | else |
| 50 | { |
| 51 | throw runtime_error("One of the valid options is required. Refer " |
| 52 | "--help for list of options."); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | catch (exception& e) |
| 57 | { |
| 58 | cerr << e.what(); |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |