summaryrefslogtreecommitdiffstats
path: root/app.cpp
blob: 96c9ee4090aaeb0008a58c31e4a15b38431168c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "args.hpp"
#include "defines.hpp"
#include "parser.hpp"
#include "write.hpp"

#include <exception>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

int main(int argc, char** argv)
{
    int rc = 0;

    try
    {
        using namespace openpower::vpd;

        args::Args arguments = args::parse(argc, argv);

        // We need vpd file, FRU type and object path
        if ((arguments.end() != arguments.find("vpd")) &&
            (arguments.end() != arguments.find("fru")) &&
            (arguments.end() != arguments.find("object")))
        {
            // Read binary VPD file
            auto file = arguments.at("vpd")[0];
            std::ifstream vpdFile(file, std::ios::binary);
            Binary vpd((std::istreambuf_iterator<char>(vpdFile)),
                       std::istreambuf_iterator<char>());

            // Parse vpd
            auto vpdStore = parse(std::move(vpd));

            using argList = std::vector<std::string>;
            argList frus = std::move(arguments.at("fru"));
            argList objects = std::move(arguments.at("object"));

            if (frus.size() != objects.size())
            {
                std::cerr << "Unequal number of FRU types and object paths "
                             "specified\n";
                rc = -1;
            }
            else
            {
                // Write VPD to FRU inventory
                for (std::size_t index = 0; index < frus.size(); ++index)
                {
                    inventory::write(frus[index], vpdStore, objects[index]);
                }
            }
        }
        else
        {
            std::cerr << "Need VPD file, FRU type and object path\n";
            rc = -1;
        }
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << "\n";
    }

    return rc;
}
OpenPOWER on IntegriCloud