blob: f682a42ca6b91be17d7d8e7e1fa9188d4e75f4ca [file] [log] [blame]
Aatir186ce8c2019-10-20 15:13:39 -05001#include "../pel.hpp"
2
3#include <CLI/CLI.hpp>
4#include <iostream>
5#include <string>
6
7using namespace phosphor::logging;
8using namespace openpower::pels;
9
10/**
11 * @brief get data form raw PEL file.
12 * @param[in] std::string Name of file with raw PEL
13 * @return std::vector<uint8_t> char vector read from raw PEL file.
14 */
15std::vector<uint8_t> getFileData(std::string name)
16{
17 std::ifstream file(name, std::ifstream::in);
18 if (file.good())
19 {
20 std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
21 std::istreambuf_iterator<char>()};
22 return data;
23 }
24 else
25 {
26 printf("Can't open raw PEL file");
27 return {};
28 }
29}
30
31static void exitWithError(const std::string& help, const char* err)
32{
33 std::cerr << "ERROR: " << err << std::endl << help << std::endl;
34 exit(-1);
35}
36
37int main(int argc, char** argv)
38{
39 CLI::App app{"OpenBMC PEL Tool"};
40 std::string fileName;
41 app.add_option("-f,--file", fileName, "Raw PEL File");
42 CLI11_PARSE(app, argc, argv);
43
44 if (!fileName.empty())
45 {
46 std::vector<uint8_t> data = getFileData(fileName);
47 if (!data.empty())
48 {
49 PEL pel{data};
50 pel.toJSON();
51 }
52 else
53 {
54 exitWithError(app.help("", CLI::AppFormatMode::All),
55 "Raw PEL file can't be read.");
56 }
57 }
58 else
59 {
60 exitWithError(app.help("", CLI::AppFormatMode::All),
61 "Raw PEL file path not specified.");
62 }
63 return 0;
64}