blob: d988f63f747ad8092d9d586171cdb506d420dba0 [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{};
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +053016 string recordName{};
17 string keyword{};
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053018
19 auto object =
20 app.add_option("--object, -O", objectPath, "Enter the Object Path");
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +053021 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");
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053024
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
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +053035 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
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053045 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
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +053064 else if (*readFlag)
65 {
66 VpdTool vpdToolObj(move(objectPath), move(recordName),
67 move(keyword));
68 vpdToolObj.readKeyword();
69 }
70
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053071 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}