X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fcli_repack.cpp;h=6f08896e1eb99e102b42e857fe516a0f15490edf;hb=940cdb8b143455fe2fc002ffd50f5e2ffcaf1260;hp=a92723d60ddaa59af5c43c0adf2bd0db77ac2f85;hpb=2ae3c962d308ceb866f7478866cdcc85f50a987d;p=apitrace diff --git a/cli/cli_repack.cpp b/cli/cli_repack.cpp index a92723d..6f08896 100644 --- a/cli/cli_repack.cpp +++ b/cli/cli_repack.cpp @@ -25,6 +25,8 @@ #include +#include + #include #include "cli.hpp" @@ -46,6 +48,15 @@ usage(void) << "\n"; } +const static char * +shortOptions = "h"; + +const static struct option +longOptions[] = { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} +}; + static int repack(const char *inFileName, const char *outFileName) { @@ -78,34 +89,26 @@ repack(const char *inFileName, const char *outFileName) static int command(int argc, char *argv[]) { - int i; - - for (i = 1; i < argc; ++i) { - const char *arg = argv[i]; - - if (arg[0] != '-') { - break; - } - - if (!strcmp(arg, "--")) { - break; - } else if (strcmp(arg, "--help") == 0) { + int opt; + while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) { + switch (opt) { + case 'h': usage(); return 0; - } else { - std::cerr << "error: unknown option " << arg << "\n"; + default: + std::cerr << "error: unexpected option `" << opt << "`\n"; usage(); return 1; } } - if (argc != i + 2) { + if (argc != optind + 2) { std::cerr << "error: insufficient number of arguments\n"; usage(); return 1; } - return repack(argv[i], argv[i + 1]); + return repack(argv[optind], argv[optind + 1]); } const Command repack_command = {