VPD tool : dumpInventory & dumpObject

VPD tool has four options.

a) Dump Complete Inventory - no additional arguments are needed.
b) Dump Specific Object - by providing the object name.
c) Read the keyword - by providing the object name, record name and keyword to be read.
d) Write/Update the keyword - by providing the object name,  record name, keyword and the value to be updated.

{value - in ascii or hex & all the other arguments in string}

"--help" option provides details on how to use the above mentioned options.

This commit has implementation of dump inventory and dump specific object.

Output:

---------Dump Inventory---------
Not displaying the complete output.

root@rainier:/tmp# ./vpd-tool -i
[
    {
        "/system": {
            "LocationCode": "U9105.22A.SIMP10R",
            "Model": "9105-22A",
            "SerialNumber": "SIMP10R",
            "type": "xyz.openbmc_project.Inventory.Item.System"
        },
        "/system/chassis": {
            "LocationCode": "U78DA.ND1.1234567",
            "type": "xyz.openbmc_project.Inventory.Item.Chassis"
        },
        .
        .
        .
        .
       and so on..
]

---------Dump Object----------

root@rainier:/tmp# ./vpd-tool -o -O /system/chassis/motherboard/ebmc_card_bmc
[
    {
        "/system/chassis/motherboard/ebmc_card_bmc": {
            "CC": "6B58",
            "DR": "EBMC            ",
            "FN": "F191014",
            "LocationCode": "U78DA.ND1.1234567-P0-C5",
            "PN": "PN12345",
            "SN": "YL6B58010000",
            "type": "xyz.openbmc_project.Inventory.Item.Bmc"
        }
    }
]

Flag to enable VPD tool:
There is no seperate flag for VPD tool.
ibm-parser flag will generate the vpd-tool binary.

Steps to build and generate the executable using meson:
meson -Denabled=ibm-parser build
ninja -C build

Test:
Tested on simics.

Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: I712f7ad4303eefa68f232685b6b0e53646f859f5
diff --git a/vpd_tool.cpp b/vpd_tool.cpp
new file mode 100644
index 0000000..0498761
--- /dev/null
+++ b/vpd_tool.cpp
@@ -0,0 +1,62 @@
+#include "vpd_tool_impl.hpp"
+
+#include <CLI/CLI.hpp>
+#include <fstream>
+#include <iostream>
+
+using namespace CLI;
+using namespace std;
+
+int main(int argc, char** argv)
+{
+    App app{"VPD Command line tool to dump the inventory and to read and "
+            "update the keywords"};
+
+    string objectPath{};
+
+    auto object =
+        app.add_option("--object, -O", objectPath, "Enter the Object Path");
+
+    auto dumpObjFlag =
+        app.add_flag("--dumpObject, -o",
+                     "Dump the given object from the inventory. { "
+                     "vpd-tool-exe --dumpObject/-o --object/-O object-name }")
+            ->needs(object);
+
+    auto dumpInvFlag = app.add_flag(
+        "--dumpInventory, -i", "Dump all the inventory objects. { vpd-tool-exe "
+                               "--dumpInventory/-i }");
+
+    CLI11_PARSE(app, argc, argv);
+
+    ifstream inventoryJson(INVENTORY_JSON);
+    auto jsObject = json::parse(inventoryJson);
+
+    try
+    {
+        if (*dumpObjFlag)
+        {
+            VpdTool vpdToolObj(move(objectPath));
+            vpdToolObj.dumpObject(jsObject);
+        }
+
+        else if (*dumpInvFlag)
+        {
+            VpdTool vpdToolObj;
+            vpdToolObj.dumpInventory(jsObject);
+        }
+
+        else
+        {
+            throw runtime_error("One of the valid options is required. Refer "
+                                "--help for list of options.");
+        }
+    }
+
+    catch (exception& e)
+    {
+        cerr << e.what();
+    }
+
+    return 0;
+}