argument: Slightly simplify option parsing logic
Do so to fix cppcoreguidelines-pro-bounds-pointer-arithmetic and
readability-implicit-bool-conversion:
```
../argument.cpp:43:13: error: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic,-warnings-as-errors]
++i;
^
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../argument.cpp:46:13: error: implicit conversion 'int' -> bool [readability-implicit-bool-conversion,-warnings-as-errors]
if (i->val)
^
!= 0
/home/andrew/src/openbmc/phosphor-led-sysfs/build/../argument.cpp:48:35: error: implicit conversion 'int' -> bool [readability-implicit-bool-conversion,-warnings-as-errors]
arguments[i->name] = (i->has_arg ? optarg : true_string);
^
!= 0
```
Change-Id: If3d950d17e9f8117246cffdb9305262a18cf8aa1
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/argument.cpp b/argument.cpp
index 563bcfb..acb9366 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -25,30 +25,22 @@
{
namespace led
{
-
-const std::string ArgumentParser::true_string = "true";
-
ArgumentParser::ArgumentParser(int argc, char** argv)
{
int option = 0;
while (-1 !=
(option = getopt_long(argc, argv, optionstr, &options[0], nullptr)))
{
- if ((option == '?') || (option == 'h'))
+ switch (option)
{
- usage(argv);
- exit(-1);
- }
-
- const auto* i = &options[0];
- while ((i->val != option) && (i->val != 0))
- {
- ++i;
- }
-
- if (i->val)
- {
- arguments[i->name] = (i->has_arg ? optarg : true_string);
+ case '?':
+ case 'h':
+ usage(argv);
+ exit(-1);
+ break;
+ case 'p':
+ arguments["path"] = optarg;
+ break;
}
}
}