This instance of Gitlab will be upgraded to 13.9 at 13.00 CEST / 11.00 UTC. It will be unavailable for some moment. Thanks for your understanding.

Commit 24b424a4 authored by Natanael Copa's avatar Natanael Copa

apk: added option --version/-V

Both variants should work:
 apk --version
 apk <applet> --version
parent f88f8205
......@@ -38,13 +38,17 @@ void apk_log(const char *prefix, const char *format, ...)
fprintf(stderr, "\n");
}
int version(void)
{
printf("apk-tools " APK_VERSION "\n");
return 0;
}
int usage(void)
{
struct apk_applet **a, *applet;
printf("apk-tools " APK_VERSION "\n"
"\n"
"Usage:\n");
version();
printf("\nUsage:\n");
for (a = &__start_apkapplets; a < &__stop_apkapplets; a++) {
applet = *a;
......@@ -95,12 +99,13 @@ static struct apk_applet *deduce_applet(int argc, char **argv)
return NULL;
}
#define NUM_GENERIC_OPTS 5
#define NUM_GENERIC_OPTS 6
static struct option generic_options[32] = {
{ "root", required_argument, NULL, 'p' },
{ "repository", required_argument, NULL, 'X' },
{ "quiet", no_argument, NULL, 'q' },
{ "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, 'V' },
{ "progress", no_argument, NULL, 0x100 },
};
......@@ -117,14 +122,17 @@ int main(int argc, char **argv)
apk_root = getenv("ROOT");
applet = deduce_applet(argc, argv);
if (applet == NULL)
return usage();
if (applet != NULL) {
if (applet->num_options && applet->options) {
memcpy(&generic_options[NUM_GENERIC_OPTS],
applet->options,
applet->num_options * sizeof(struct option));
}
if (applet->num_options && applet->options) {
memcpy(&generic_options[NUM_GENERIC_OPTS],
applet->options,
applet->num_options * sizeof(struct option));
if (applet->context_size != 0)
ctx = calloc(1, applet->context_size);
}
for (opt = &generic_options[0], sopt = short_options;
opt->name != NULL; opt++) {
if (opt->flag == NULL &&
......@@ -135,9 +143,6 @@ int main(int argc, char **argv)
}
}
if (applet->context_size != 0)
ctx = calloc(1, applet->context_size);
optindex = 0;
while ((r = getopt_long(argc, argv, short_options,
generic_options, &optindex)) != -1) {
......@@ -154,11 +159,14 @@ int main(int argc, char **argv)
case 'v':
apk_verbosity++;
break;
case 'V':
return version();
break;
case 0x100:
apk_progress = 1;
break;
default:
if (applet->parse == NULL)
if (applet == NULL || applet->parse == NULL)
return usage();
if (applet->parse(ctx, r, optindex - NUM_GENERIC_OPTS,
optarg) != 0)
......@@ -167,6 +175,9 @@ int main(int argc, char **argv)
}
}
if (applet == NULL)
return usage();
if (apk_root == NULL)
apk_root = "/";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment