rots: add list of subcommands with descriptions and implement usage

master
S.J.R. van Schaik 7 years ago
parent 7cf51a56ad
commit 01270673a3
  1. 45
      source/main.c

@ -8,27 +8,47 @@
#include <unpack.h> #include <unpack.h>
#include <verify.h> #include <verify.h>
struct entry_point { struct entry {
const char *cmd; const char *cmd;
int (* main)(int argc, char *argv[]); int (* main)(int argc, char *argv[]);
char *desc;
}; };
struct entry_point entries[] = { struct entry entries[] = {
{ "get-offset", do_get_offset }, { "get-offset", do_get_offset,
{ "get-size", do_get_size }, "print the offset of the payload within an image" },
{ "pack", do_pack }, { "get-size", do_get_size,
{ "sign", do_sign }, "print the size of the payload within an image" },
{ "unpack", do_unpack }, { "pack", do_pack,
{ "verify", do_verify }, "pack the payload within an image" },
{ NULL, NULL }, { "sign", do_sign,
"sign an image" },
{ "unpack", do_unpack,
"unpack the payload of an image" },
{ "verify", do_verify,
"verify the signatures of an image" },
{ NULL, NULL, NULL },
}; };
static void show_usage(const char *prog_name)
{
struct entry *entry;
fprintf(stderr, "usage: %s <command> ...\n\n"
"ROTS utilities to work with signed images\n\n"
"Available commands:\n", prog_name);
for (entry = entries; entry->cmd; ++entry) {
fprintf(stderr, "\t%-16s %-80s\n", entry->cmd, entry->desc);
}
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct entry_point *entry; struct entry *entry;
if (argc < 2) { if (argc < 2) {
fprintf(stderr, "usage: %s <command>\n", argv[0]); show_usage(argv[0]);
return -1; return -1;
} }
@ -37,6 +57,7 @@ int main(int argc, char *argv[])
return entry->main(argc, argv); return entry->main(argc, argv);
} }
fprintf(stderr, "usage: %s <command>\n", argv[0]); show_usage(argv[0]);
return -1; return -1;
} }

Loading…
Cancel
Save