summaryrefslogtreecommitdiffstats
path: root/argument.cpp
diff options
context:
space:
mode:
authorLei YU <mine260309@gmail.com>2018-04-11 13:33:25 +0800
committerLei YU <mine260309@gmail.com>2018-04-12 10:13:51 +0800
commitbc4a4ff6e4d0688727d54e73356be617acf18035 (patch)
tree98156f5981f90cbff29ae809f2419dc18b6ff770 /argument.cpp
parente0573e2e389a3ba1f974ae2ab0c71526634256c8 (diff)
downloadphosphor-gpio-monitor-bc4a4ff6e4d0688727d54e73356be617acf18035.tar.gz
phosphor-gpio-monitor-bc4a4ff6e4d0688727d54e73356be617acf18035.zip
Add --continue argument
The monitor will exit when key is pressed. Add --continue argument and if it is set to "true", the monitor will continue after key is pressed. This is useful in cases to monitor a button presses. E.g. It can be used to monitor ID button and start a system unit everytime when the button is pressed. This argument is optional so it does not break the current code. Tested: With "--continue=true", the monitor does not exit when the key is pressed. Without the argument of if it is set to other strings, the monitor exits after the key is pressed. Change-Id: I4f2ca16d7b26e10397181c83c2c5947ed5ce091f Signed-off-by: Lei YU <mine260309@gmail.com>
Diffstat (limited to 'argument.cpp')
-rw-r--r--argument.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/argument.cpp b/argument.cpp
index 41cf6f7..d388001 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -37,6 +37,7 @@ const option ArgumentParser::options[] =
{ "key", required_argument, nullptr, 'k' },
{ "polarity", required_argument, nullptr, 'r' },
{ "target", required_argument, nullptr, 't' },
+ { "continue", optional_argument, nullptr, 'c' },
{ "help", no_argument, nullptr, 'h' },
{ 0, 0, 0, 0},
};
@@ -60,7 +61,10 @@ ArgumentParser::ArgumentParser(int argc, char** argv)
if (i->val)
{
- arguments[i->name] = (i->has_arg ? optarg : trueString);
+ // optinal argument may get nullptr for optarg
+ // make it empty string in such case
+ auto arg = (optarg == nullptr ? "" : optarg);
+ arguments[i->name] = (i->has_arg ? arg : trueString);
}
}
}
@@ -90,6 +94,8 @@ void ArgumentParser::usage(char** argv)
" This is 0 / 1 \n";
std::cerr << " --target=<systemd unit> Systemd unit to be called on GPIO"
" state change\n";
+ std::cerr << " --continue=[true] Whether or not to continue"
+ " after key pressed\n";
}
} // namespace gpio
} // namespace phosphor
OpenPOWER on IntegriCloud