blob: 96c9ee4090aaeb0008a58c31e4a15b38431168c2 [file] [log] [blame]
Deepak Kodihalli51748cf2016-11-28 05:00:44 -06001#include "args.hpp"
Patrick Venturec83c4dc2018-11-01 16:29:18 -07002#include "defines.hpp"
Deepak Kodihalli51748cf2016-11-28 05:00:44 -06003#include "parser.hpp"
Patrick Venturec83c4dc2018-11-01 16:29:18 -07004#include "write.hpp"
5
6#include <exception>
7#include <fstream>
8#include <iostream>
9#include <iterator>
10#include <string>
11#include <vector>
Deepak Kodihalli51748cf2016-11-28 05:00:44 -060012
13int main(int argc, char** argv)
14{
15 int rc = 0;
16
17 try
18 {
19 using namespace openpower::vpd;
20
Patrick Venturec83c4dc2018-11-01 16:29:18 -070021 args::Args arguments = args::parse(argc, argv);
Deepak Kodihalli51748cf2016-11-28 05:00:44 -060022
23 // We need vpd file, FRU type and object path
24 if ((arguments.end() != arguments.find("vpd")) &&
25 (arguments.end() != arguments.find("fru")) &&
26 (arguments.end() != arguments.find("object")))
27 {
28 // Read binary VPD file
29 auto file = arguments.at("vpd")[0];
30 std::ifstream vpdFile(file, std::ios::binary);
31 Binary vpd((std::istreambuf_iterator<char>(vpdFile)),
32 std::istreambuf_iterator<char>());
33
34 // Parse vpd
35 auto vpdStore = parse(std::move(vpd));
36
37 using argList = std::vector<std::string>;
38 argList frus = std::move(arguments.at("fru"));
39 argList objects = std::move(arguments.at("object"));
40
41 if (frus.size() != objects.size())
42 {
43 std::cerr << "Unequal number of FRU types and object paths "
Patrick Venturec83c4dc2018-11-01 16:29:18 -070044 "specified\n";
Deepak Kodihalli51748cf2016-11-28 05:00:44 -060045 rc = -1;
46 }
47 else
48 {
49 // Write VPD to FRU inventory
50 for (std::size_t index = 0; index < frus.size(); ++index)
51 {
Patrick Venturec83c4dc2018-11-01 16:29:18 -070052 inventory::write(frus[index], vpdStore, objects[index]);
Deepak Kodihalli51748cf2016-11-28 05:00:44 -060053 }
54 }
55 }
56 else
57 {
58 std::cerr << "Need VPD file, FRU type and object path\n";
59 rc = -1;
60 }
61 }
62 catch (std::exception& e)
63 {
64 std::cerr << e.what() << "\n";
65 }
66
67 return rc;
68}