summaryrefslogtreecommitdiff
path: root/src/ver.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-10-08 15:29:27 +0300
committerTimo Teräs <timo.teras@iki.fi>2014-10-08 15:29:27 +0300
commit38e3f5463878a29e675be8430135e36b552c0ac1 (patch)
tree6487e72ccb5a65d804b3f768cd22cf353df039b8 /src/ver.c
parent275dd16c42b7208723cfa84ac9c6eb0dcb8071b6 (diff)
downloadapk-tools-38e3f5463878a29e675be8430135e36b552c0ac1.tar.gz
apk-tools-38e3f5463878a29e675be8430135e36b552c0ac1.tar.bz2
apk-tools-38e3f5463878a29e675be8430135e36b552c0ac1.tar.xz
apk-tools-38e3f5463878a29e675be8430135e36b552c0ac1.zip
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.
Diffstat (limited to 'src/ver.c')
-rw-r--r--src/ver.c34
1 files changed, 19 insertions, 15 deletions
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,
};