aboutsummaryrefslogtreecommitdiffstats
path: root/src/dot.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/dot.c
parent275dd16c42b7208723cfa84ac9c6eb0dcb8071b6 (diff)
downloadaports-38e3f5463878a29e675be8430135e36b552c0ac1.tar.bz2
aports-38e3f5463878a29e675be8430135e36b552c0ac1.tar.xz
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/dot.c')
-rw-r--r--src/dot.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/dot.c b/src/dot.c
index ccf5435c57..9c8ed4e993 100644
--- a/src/dot.c
+++ b/src/dot.c
@@ -24,8 +24,7 @@ struct dot_ctx {
int installed_only : 1;
};
-static int dot_parse(void *pctx, struct apk_db_options *dbopts,
- int optch, int optindex, const char *optarg)
+static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg)
{
struct dot_ctx *ctx = (struct dot_ctx *) pctx;
@@ -38,11 +37,24 @@ static int dot_parse(void *pctx, struct apk_db_options *dbopts,
dbopts->open_flags &= ~APK_OPENF_NO_INSTALLED;
break;
default:
- return -1;
+ return -ENOTSUP;
}
return 0;
}
+static const struct apk_option options_applet[] = {
+ { 0x10000, "errors", "Output only parts of the graph which are considered "
+ "erroneous: e.g. cycles and missing packages" },
+ { 0x10001, "installed", "Consider only installed packages" },
+};
+
+static const struct apk_option_group optgroup_applet = {
+ .name = "Dot",
+ .options = options_applet,
+ .num_options = ARRAY_SIZE(options_applet),
+ .parse = option_parse_applet,
+};
+
static void start_graph(struct dot_ctx *ctx)
{
if (ctx->not_empty)
@@ -155,21 +167,13 @@ static int dot_main(void *pctx, struct apk_database *db, struct apk_string_array
return 0;
}
-static struct apk_option dot_options[] = {
- { 0x10000, "errors", "Output only parts of the graph which are considered "
- "erroneous: e.g. cycles and missing packages" },
- { 0x10001, "installed", "Consider only installed packages" },
-};
-
static struct apk_applet apk_dot = {
.name = "dot",
.help = "Generate graphviz graphs",
.arguments = "PKGMASK...",
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE,
.context_size = sizeof(struct dot_ctx),
- .num_options = ARRAY_SIZE(dot_options),
- .options = dot_options,
- .parse = dot_parse,
+ .optgroups = { &optgroup_global, &optgroup_applet },
.main = dot_main,
};