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