blob: f682a42ca6b91be17d7d8e7e1fa9188d4e75f4ca [file] [log] [blame]
#include "../pel.hpp"
#include <CLI/CLI.hpp>
#include <iostream>
#include <string>
using namespace phosphor::logging;
using namespace openpower::pels;
/**
* @brief get data form raw PEL file.
* @param[in] std::string Name of file with raw PEL
* @return std::vector<uint8_t> char vector read from raw PEL file.
*/
std::vector<uint8_t> getFileData(std::string name)
{
std::ifstream file(name, std::ifstream::in);
if (file.good())
{
std::vector<uint8_t> data{std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>()};
return data;
}
else
{
printf("Can't open raw PEL file");
return {};
}
}
static void exitWithError(const std::string& help, const char* err)
{
std::cerr << "ERROR: " << err << std::endl << help << std::endl;
exit(-1);
}
int main(int argc, char** argv)
{
CLI::App app{"OpenBMC PEL Tool"};
std::string fileName;
app.add_option("-f,--file", fileName, "Raw PEL File");
CLI11_PARSE(app, argc, argv);
if (!fileName.empty())
{
std::vector<uint8_t> data = getFileData(fileName);
if (!data.empty())
{
PEL pel{data};
pel.toJSON();
}
else
{
exitWithError(app.help("", CLI::AppFormatMode::All),
"Raw PEL file can't be read.");
}
}
else
{
exitWithError(app.help("", CLI::AppFormatMode::All),
"Raw PEL file path not specified.");
}
return 0;
}