From 38e3f5463878a29e675be8430135e36b552c0ac1 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Wed, 8 Oct 2014 15:29:27 +0300 Subject: rework option parsing to have a group structure Add also a new 'commit' group that is the common options for all applets that can commit package changes. --- src/ver.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/ver.c') diff --git a/src/ver.c b/src/ver.c index 6469db4..53ef062 100644 --- a/src/ver.c +++ b/src/ver.c @@ -68,11 +68,10 @@ static int ver_validate(struct apk_database *db, struct apk_string_array *args) return errors; } -static int ver_parse(void *ctx, struct apk_db_options *dbopts, - int opt, int optindex, const char *optarg) +static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int optch, const char *optarg) { struct ver_ctx *ictx = (struct ver_ctx *) ctx; - switch (opt) { + switch (optch) { case 'I': ictx->action = ver_indexes; break; @@ -96,6 +95,22 @@ static int ver_parse(void *ctx, struct apk_db_options *dbopts, return 0; } +static const struct apk_option options_applet[] = { + { 'I', "indexes", "Print description and versions of indexes" }, + { 't', "test", "Compare two given versions, output '<', '=' or '>'" }, + { 'c', "check", "Check the given version strings, output any that are invalid" }, + { 'a', "all", "Consider packages from all repository tags" }, + { 'l', "limit", "Limit output to packages with status matching one of LIMCHARs", + required_argument, "LIMCHARs" }, +}; + +static const struct apk_option_group optgroup_applet = { + .name = "Version", + .options = options_applet, + .num_options = ARRAY_SIZE(options_applet), + .parse = option_parse_applet, +}; + static void ver_print_package_status(struct apk_database *db, const char *match, struct apk_name *name, void *pctx) { struct ver_ctx *ctx = (struct ver_ctx *) pctx; @@ -181,24 +196,13 @@ static int ver_main(void *pctx, struct apk_database *db, struct apk_string_array return 0; } -static struct apk_option ver_options[] = { - { 'I', "indexes", "Print description and versions of indexes" }, - { 't', "test", "Compare two given versions, output '<', '=' or '>'" }, - { 'c', "check", "Check the given version strings, output any that are invalid" }, - { 'a', "all", "Consider packages from all repository tags" }, - { 'l', "limit", "Limit output to packages with status matching one of LIMCHARs", - required_argument, "LIMCHARs" }, -}; - static struct apk_applet apk_ver = { .name = "version", .help = "Compare package versions (in installed database vs. available) " "or do tests on literal version strings", .open_flags = APK_OPENF_READ, .context_size = sizeof(struct ver_ctx), - .num_options = ARRAY_SIZE(ver_options), - .options = ver_options, - .parse = ver_parse, + .optgroups = { &optgroup_global, &optgroup_applet }, .main = ver_main, }; -- cgit v1.2.3-70-g09d2