summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2020-06-26 11:09:41 +0000
committerGitHub <noreply@github.com>2020-06-26 11:09:41 +0000
commit3602bd64b84c20186bb72ce209b8b0023b0c50f9 (patch)
treeaa2fa6bfddc03d89b04d06d6bfd00132b0572cce
parentd1fbcbbde594eb64a7c20aa44be7107e8b85f61d (diff)
parent6282816b1cc294b1bf735bcddabd2955c8731050 (diff)
downloadgenimage-3602bd64b84c20186bb72ce209b8b0023b0c50f9.tar.gz
genimage-3602bd64b84c20186bb72ce209b8b0023b0c50f9.tar.xz
Merge pull request #111 from leojrfs/add-version
introduce `-v/--version` option
-rw-r--r--config.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/config.c b/config.c
index b0dd721..943191c 100644
--- a/config.c
+++ b/config.c
@@ -44,7 +44,8 @@ static void show_help(const char *cmd)
"Generate filesystem, disk and flash images defined in the\n"
"configuration file.\n\n"
"Valid options: [ default value ] (environment variable)\n"
- " -h, --help\n", cmd);
+ " -h, --help\n"
+ " -v, --version\n", cmd);
list_for_each_entry(c, &optlist, list) {
char opt[20], def[20];
snprintf(opt, 20, "%s <arg>", c->name);
@@ -54,6 +55,11 @@ static void show_help(const char *cmd)
printf("\n");
}
+static void show_version(void)
+{
+ printf(PACKAGE_VERSION "\n");
+}
+
/*
* get the value of an option
*/
@@ -218,7 +224,7 @@ int set_config_opts(int argc, char *argv[], cfg_t *cfg)
/* and last but not least from command line switches */
- long_options = xzalloc(sizeof(struct option) * (num_opts + 2));
+ long_options = xzalloc(sizeof(struct option) * (num_opts + 3));
i = 0;
@@ -230,12 +236,14 @@ int set_config_opts(int argc, char *argv[], cfg_t *cfg)
}
long_options[i].name = "help";
long_options[i].val = 'h';
+ long_options[i+1].name = "version";
+ long_options[i+1].val = 'v';
optind = 1;
while (1) {
int option_index = 0;
- n = getopt_long(argc, argv, "h",
+ n = getopt_long(argc, argv, "hv",
long_options, &option_index);
if (n == -1)
break;
@@ -249,6 +257,10 @@ int set_config_opts(int argc, char *argv[], cfg_t *cfg)
show_help(argv[0]);
exit(0);
break;
+ case 'v':
+ show_version();
+ exit(0);
+ break;
default:
ret = -EINVAL;
goto err_out;