summaryrefslogtreecommitdiff
path: root/src/fetch.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/fetch.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/fetch.c')
-rw-r--r--src/fetch.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/fetch.c b/src/fetch.c
index 22ea648..3c40963 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -67,8 +67,7 @@ static int cup(void)
return write(STDOUT_FILENO, buf, len) != len;
}
-static int fetch_parse(void *ctx, struct apk_db_options *dbopts,
- int optch, int optindex, const char *optarg)
+static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int optch, const char *optarg)
{
struct fetch_ctx *fctx = (struct fetch_ctx *) ctx;
@@ -86,11 +85,27 @@ static int fetch_parse(void *ctx, struct apk_db_options *dbopts,
fctx->outdir_fd = openat(AT_FDCWD, optarg, O_RDONLY | O_CLOEXEC);
break;
default:
- return -1;
+ return -ENOTSUP;
}
return 0;
}
+static const struct apk_option options_applet[] = {
+ { 'L', "link", "Create hard links if possible" },
+ { 'R', "recursive", "Fetch the PACKAGE and all its dependencies" },
+ { 's', "stdout",
+ "Dump the .apk to stdout (incompatible with -o, -R, --progress)" },
+ { 'o', "output", "Directory to place the PACKAGEs to",
+ required_argument, "DIR" },
+};
+
+static const struct apk_option_group optgroup_applet = {
+ .name = "Fetch",
+ .options = options_applet,
+ .num_options = ARRAY_SIZE(options_applet),
+ .parse = option_parse_applet,
+};
+
static void progress_cb(void *pctx, size_t bytes_done)
{
struct fetch_ctx *ctx = (struct fetch_ctx *) pctx;
@@ -263,15 +278,6 @@ static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_arr
return ctx->errors;
}
-static struct apk_option fetch_options[] = {
- { 'L', "link", "Create hard links if possible" },
- { 'R', "recursive", "Fetch the PACKAGE and all its dependencies" },
- { 's', "stdout",
- "Dump the .apk to stdout (incompatible with -o, -R, --progress)" },
- { 'o', "output", "Directory to place the PACKAGEs to",
- required_argument, "DIR" },
-};
-
static struct apk_applet apk_fetch = {
.name = "fetch",
.help = "Download PACKAGEs from global repositories to a local directory",
@@ -279,9 +285,7 @@ static struct apk_applet apk_fetch = {
.open_flags = APK_OPENF_READ | APK_OPENF_NO_STATE |
APK_OPENF_NO_INSTALLED_REPO,
.context_size = sizeof(struct fetch_ctx),
- .num_options = ARRAY_SIZE(fetch_options),
- .options = fetch_options,
- .parse = fetch_parse,
+ .optgroups = { &optgroup_global, &optgroup_applet },
.main = fetch_main,
};