summaryrefslogtreecommitdiff
path: root/futility/cmd_pcr.c
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2015-03-11 11:21:47 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-03-18 23:07:36 +0000
commit01466d36afd10b3947de475bc9b4fb23848e81ce (patch)
tree331e22905fc988641f111cdb5bd49b7970207290 /futility/cmd_pcr.c
parent49a422fab9afb3f013ee6115738c7e13d9ec8191 (diff)
downloadvboot-01466d36afd10b3947de475bc9b4fb23848e81ce.tar.gz
futility: Let each command provide its own help
Instead of a separate help function for each command, let's just require each command to handle a --help option. This will make it easier to layer the commands (for example, "sign" could have several subcommand variants, each with its own help). BUG=none BRANCH=none TEST=make runtests I also compared the result of running "futility help CMD" before and after this change. The help still shows up correctly. Change-Id: I5c58176f32b41b0a2c2b8f0afb17dddd80fddc70 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/260495 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility/cmd_pcr.c')
-rw-r--r--futility/cmd_pcr.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/futility/cmd_pcr.c b/futility/cmd_pcr.c
index 0de234dc..241bfb2f 100644
--- a/futility/cmd_pcr.c
+++ b/futility/cmd_pcr.c
@@ -96,7 +96,13 @@ static void print_digest(const uint8_t *buf, int len)
printf("%02x", buf[i]);
}
-
+enum {
+ OPT_HELP = 1000,
+};
+static const struct option long_opts[] = {
+ {"help", 0, 0, OPT_HELP},
+ {NULL, 0, 0, 0}
+};
static int do_pcr(int argc, char *argv[])
{
uint8_t accum[SHA256_DIGEST_SIZE * 2];
@@ -109,7 +115,7 @@ static int do_pcr(int argc, char *argv[])
int i;
opterr = 0; /* quiet, you */
- while ((i = getopt(argc, argv, ":i2")) != -1) {
+ while ((i = getopt_long(argc, argv, ":i2", long_opts, NULL)) != -1) {
switch (i) {
case 'i':
opt_init = 1;
@@ -118,6 +124,9 @@ static int do_pcr(int argc, char *argv[])
digest_alg = SHA256_DIGEST_ALGORITHM;
digest_size = SHA256_DIGEST_SIZE;
break;
+ case OPT_HELP:
+ print_help(argc, argv);
+ return !!errorcnt;
case '?':
if (optopt)
fprintf(stderr, "Unrecognized option: -%c\n",
@@ -181,7 +190,5 @@ static int do_pcr(int argc, char *argv[])
return 0;
}
-DECLARE_FUTIL_COMMAND(pcr, do_pcr,
- VBOOT_VERSION_ALL,
- "Simulate a TPM PCR extension operation",
- print_help);
+DECLARE_FUTIL_COMMAND(pcr, do_pcr, VBOOT_VERSION_ALL,
+ "Simulate a TPM PCR extension operation");