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 <verify.h>
struct entry_point {
struct entry {
const char *cmd;
int (* main)(int argc, char *argv[]);
char *desc;
};
struct entry_point entries[] = {
{ "get-offset", do_get_offset },
{ "get-size", do_get_size },
{ "pack", do_pack },
{ "sign", do_sign },
{ "unpack", do_unpack },
{ "verify", do_verify },
{ NULL, NULL },
struct entry entries[] = {
{ "get-offset", do_get_offset,
"print the offset of the payload within an image" },
{ "get-size", do_get_size,
"print the size of the payload within an image" },
{ "pack", do_pack,
"pack the payload within an image" },
{ "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[])
{
struct entry_point *entry;
struct entry *entry;
if (argc < 2) {
fprintf(stderr, "usage: %s <command>\n", argv[0]);
show_usage(argv[0]);
return -1;
}
@ -37,6 +57,7 @@ int main(int argc, char *argv[])
return entry->main(argc, argv);
}
fprintf(stderr, "usage: %s <command>\n", argv[0]);
show_usage(argv[0]);
return -1;
}

Loading…
Cancel
Save