Fixup command line options
pldmtool BASE/BIOS/OEM -c/--command [GetPLDMTypes/GetPLDMVersion]
base/bios/fru/oem works
pldmtool -r/--raw 0x00 ... works
Tested:
pldmtool -h
PLDM requester tool for OpenBMC
Usage: pldmtool [SUBCOMMAND] [OPTIONS]
Options:
-h,--help Print this help message and exit
-r,--raw TEXT ... Send a RAW PLDM request and print response
Subcommands:
BASE PLDM Command Type = BASE
BIOS PLDM Command Type = BIOS
OEM PLDM Command Type = OEM
pldmtool BASE -h
PLDM Command Type = BASE
Usage: pldmtool BASE [OPTIONS]
Options:
-h,--help Print this help message and exit
-c,--command TEXT ... PLDM request command
[GetPLDMTypes] Get PLDM Type
[GetPLDMVersion] Get PLDM Version
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Idb3a09bbaefec54546e9fba8aaa82541862e7bb1
diff --git a/tool/pldmtool.cpp b/tool/pldmtool.cpp
index c3e2186..54287d5 100644
--- a/tool/pldmtool.cpp
+++ b/tool/pldmtool.cpp
@@ -10,38 +10,57 @@
// TODO: To enable it later
// bool verbose_flag = false;
// app.add_flag("-v, --verbose", verbose_flag, "Output debug logs ");
+ std::vector<std::string> rawCmd{};
+ app.add_option("-r, --raw", rawCmd,
+ "Send a RAW PLDM request and print response");
+
+ auto base = app.add_subcommand("BASE", "PLDM Command Type = BASE");
std::vector<std::string> args{};
- app.add_option("-c, —command", args, " PLDM request command");
+ base->add_option("-c, --command", args,
+ "PLDM request command \n"
+ "[GetPLDMTypes] Get PLDM Type \n"
+ "[GetPLDMVersion] Get PLDM Version");
- std::string rawCmd;
- app.add_option("raw", rawCmd, "Send a RAW PLDM request and print response");
+ auto bios = app.add_subcommand("BIOS", "PLDM Command Type = BIOS");
+ bios->add_option("-c, --command", args, "PLDM request command");
- std::string pldmCmdName;
- app.add_option("GetPLDMTypes", pldmCmdName, "Get PLDM Type");
- app.add_option("GetPLDMVersion", pldmCmdName, "Get PLDM Version");
-
- app.add_subcommand("BASE", "PLDM Command Type = BASE");
- app.add_subcommand("BIOS", "PLDM Command Type = BIOS");
- app.add_subcommand("OEM", "PLDM Command Type = OEM");
+ auto oem = app.add_subcommand("OEM", "PLDM Command Type = OEM");
+ oem->add_option("-c, --command", args, "PLDM request command");
CLI11_PARSE(app, argc, argv);
std::string cmdName;
int rc = 0;
- if (args[0] != "raw")
+ if (argc < 2)
+ {
+ std::cerr << "Run pldmtool --help for more information" << std::endl;
+ return -1;
+ }
+
+ if (memcmp(argv[1], "--raw", strlen(argv[1])) != 0 &&
+ memcmp(argv[1], "-r", strlen(argv[1])) != 0)
{
// Parse args to program
+ if (args.size() == 0)
+ {
+ std::cerr << "Run pldmtool --help for more information"
+ << std::endl;
+ return -1;
+ }
cmdName = args[0];
}
else
{
- // removing 'raw' from the args list since it is positional argument
- // and not an input value.
- args.erase(args.begin());
+ if (rawCmd.size() == 0)
+ {
+ std::cerr << "Run pldmtool --help for more information"
+ << std::endl;
+ return -1;
+ }
// loop through the remaining argument list
- for (auto&& item : args)
+ for (auto&& item : rawCmd)
{
if (item[0] == '0' && (item[1] == 'x' || item[1] == 'X'))
@@ -61,18 +80,17 @@
{
std::cerr << item << " contains non hex digits. Re-enter"
<< std::endl;
- rc = -1;
- return rc;
+ return -1;
}
}
else
{
- std::cout << item << " Input hex value starting with 0x "
+ std::cerr << item << " Input hex value starting with 0x "
<< std::endl;
- rc = -1;
- return rc;
+ return -1;
}
}
+ args = rawCmd;
}
Handler handler;
@@ -83,7 +101,8 @@
catch (const std::out_of_range& e)
{
std::cerr << cmdName << " is not supported!" << std::endl;
- rc = -1;
+ return -1;
}
+
return rc;
}