blob: 04987619c7da70106b69c3271a47cba7cb77daef [file] [log] [blame]
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +05301#include "vpd_tool_impl.hpp"
2
3#include <CLI/CLI.hpp>
4#include <fstream>
5#include <iostream>
6
7using namespace CLI;
8using namespace std;
9
10int 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}