Gitweb:
http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=7f929de6d5194ce45684738a35944f0ffaef1c6e
Commit: 7f929de6d5194ce45684738a35944f0ffaef1c6e
Parent: 47c8aa38bf7c2471df4a0ca9ee04e5204eb20cbd
Author: David Lutterkort <[email protected]>
AuthorDate: Fri Sep 11 16:00:34 2009 -0700
Committer: David Lutterkort <[email protected]>
CommitterDate: Fri Sep 11 16:11:20 2009 -0700
Add --version option to augtool and augparse
Fixes bug #88
---
src/augparse.c | 39 ++++++++++++++++++++++++++++++++++++---
src/augtool.c | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/src/augparse.c b/src/augparse.c
index 15d40ae..630af52 100644
--- a/src/augparse.c
+++ b/src/augparse.c
@@ -29,6 +29,7 @@
#include "augeas.h"
const char *progname;
+bool print_version = false;
__attribute__((noreturn))
static void usage(void) {
@@ -37,11 +38,32 @@ static void usage(void) {
fprintf(stderr, "\nOptions:\n\n");
fprintf(stderr, " -I, --include DIR search DIR for modules; can be given
mutiple times\n");
fprintf(stderr, " --nostdinc do not search the builtin default
directories for modules\n");
- fprintf(stderr, " --notyupecheck do not typecheck lenses\n");
+ fprintf(stderr, " --notypecheck do not typecheck lenses\n");
+ fprintf(stderr, " --version print version information and
exit\n");
exit(EXIT_FAILURE);
}
+static void print_version_info(struct augeas *aug) {
+ const char *version;
+ int r;
+
+ r = aug_get(aug, "/augeas/version", &version);
+ if (r != 1)
+ goto error;
+
+ fprintf(stderr, "augparse %s <http://augeas.net/>\n", version);
+ fprintf(stderr, "Copyright (C) 2009 Red Hat, Inc.\n");
+ fprintf(stderr, "License LGPLv2+: GNU LGPL version 2.1 or later\n");
+ fprintf(stderr, "
<http://www.gnu.org/licenses/lgpl-2.1.html>\n");
+ fprintf(stderr, "This is free software: you are free to change and
redistribute it.\n");
+ fprintf(stderr, "There is NO WARRANTY, to the extent permitted by
law.\n\n");
+ fprintf(stderr, "Written by David Lutterkort\n");
+ return;
+ error:
+ fprintf(stderr, "Something went terribly wrong internally - please file a
bug\n");
+}
+
int main(int argc, char **argv) {
int opt;
struct augeas *aug;
@@ -49,13 +71,15 @@ int main(int argc, char **argv) {
size_t loadpathlen = 0;
enum {
VAL_NO_STDINC = CHAR_MAX + 1,
- VAL_NO_TYPECHECK = VAL_NO_STDINC + 1
+ VAL_NO_TYPECHECK = VAL_NO_STDINC + 1,
+ VAL_VERSION = VAL_NO_TYPECHECK + 1
};
struct option options[] = {
{ "help", 0, 0, 'h' },
{ "include", 1, 0, 'I' },
{ "nostdinc", 0, 0, VAL_NO_STDINC },
{ "notypecheck", 0, 0, VAL_NO_TYPECHECK },
+ { "version", 0, 0, VAL_VERSION },
{ 0, 0, 0, 0}
};
int idx;
@@ -76,19 +100,28 @@ int main(int argc, char **argv) {
case VAL_NO_TYPECHECK:
flags &= ~(AUG_TYPE_CHECK);
break;
+ case VAL_VERSION:
+ print_version = true;
+ break;
default:
usage();
break;
}
}
- if (optind >= argc) {
+ if (!print_version && optind >= argc) {
fprintf(stderr, "Expected .aug file\n");
usage();
}
argz_stringify(loadpath, loadpathlen, PATH_SEP_CHAR);
aug = aug_init(NULL, loadpath, flags);
+
+ if (print_version) {
+ print_version_info(aug);
+ return EXIT_SUCCESS;
+ }
+
if (__aug_load_module_file(aug, argv[optind]) == -1) {
fprintf(stderr, "%s: error: Loading failed\n", argv[optind]);
exit(EXIT_FAILURE);
diff --git a/src/augtool.c b/src/augtool.c
index f7f48c3..20c7bcd 100644
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -48,6 +48,7 @@ static unsigned int flags = AUG_NONE;
const char *root = NULL;
char *loadpath = NULL;
int echo = 0;
+bool print_version = false;
static char *cleanstr(char *path, const char sep) {
if (path == NULL || strlen(path) == 0)
@@ -575,6 +576,7 @@ static void usage(void) {
fprintf(stderr, " --nostdinc do not search the builtin default
directories for modules\n");
fprintf(stderr, " --noload do not load any files into the tree
on startup\n");
fprintf(stderr, " --noautoload do not autoload modules from the
search path\n");
+ fprintf(stderr, " --version print version information and
exit.\n");
exit(EXIT_FAILURE);
}
@@ -585,7 +587,8 @@ static void parse_opts(int argc, char **argv) {
enum {
VAL_NO_STDINC = CHAR_MAX + 1,
VAL_NO_LOAD = VAL_NO_STDINC + 1,
- VAL_NO_AUTOLOAD = VAL_NO_LOAD + 1
+ VAL_NO_AUTOLOAD = VAL_NO_LOAD + 1,
+ VAL_VERSION = VAL_NO_AUTOLOAD + 1
};
struct option options[] = {
{ "help", 0, 0, 'h' },
@@ -598,6 +601,7 @@ static void parse_opts(int argc, char **argv) {
{ "nostdinc", 0, 0, VAL_NO_STDINC },
{ "noload", 0, 0, VAL_NO_LOAD },
{ "noautoload", 0, 0, VAL_NO_AUTOLOAD },
+ { "version", 0, 0, VAL_VERSION },
{ 0, 0, 0, 0}
};
int idx;
@@ -634,6 +638,10 @@ static void parse_opts(int argc, char **argv) {
case VAL_NO_AUTOLOAD:
flags |= AUG_NO_MODL_AUTOLOAD;
break;
+ case VAL_VERSION:
+ flags |= AUG_NO_MODL_AUTOLOAD;
+ print_version = true;
+ break;
default:
usage();
break;
@@ -642,6 +650,26 @@ static void parse_opts(int argc, char **argv) {
argz_stringify(loadpath, loadpathlen, PATH_SEP_CHAR);
}
+static void print_version_info(void) {
+ const char *version;
+ int r;
+
+ r = aug_get(aug, "/augeas/version", &version);
+ if (r != 1)
+ goto error;
+
+ fprintf(stderr, "augtool %s <http://augeas.net/>\n", version);
+ fprintf(stderr, "Copyright (C) 2009 Red Hat, Inc.\n");
+ fprintf(stderr, "License LGPLv2+: GNU LGPL version 2.1 or later\n");
+ fprintf(stderr, "
<http://www.gnu.org/licenses/lgpl-2.1.html>\n");
+ fprintf(stderr, "This is free software: you are free to change and
redistribute it.\n");
+ fprintf(stderr, "There is NO WARRANTY, to the extent permitted by
law.\n\n");
+ fprintf(stderr, "Written by David Lutterkort\n");
+ return;
+ error:
+ fprintf(stderr, "Something went terribly wrong internally - please file a
bug\n");
+}
+
static int main_loop(void) {
static const int maxargs = 3;
char *line = NULL;
@@ -697,6 +725,10 @@ int main(int argc, char **argv) {
fprintf(stderr, "Failed to initialize Augeas\n");
exit(EXIT_FAILURE);
}
+ if (print_version) {
+ print_version_info();
+ return EXIT_SUCCESS;
+ }
readline_init();
if (optind < argc) {
// Accept one command from the command line
_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel