[augeas-devel] [PATCH 1 of 3] augtool, augparse: allow long options

David Lutterkort lutter at redhat.com
Mon Sep 8 23:39:07 UTC 2008


2 files changed, 28 insertions(+), 12 deletions(-)
src/augparse.c |   11 +++++++++--
src/augtool.c  |   29 +++++++++++++++++++----------


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1220916636 25200
# Node ID aa37514c950092720ed1af022eb35ca1b76009a5
# Parent  29d32cd41d805484660ab03f34cc8f49c12fd203
augtool, augparse: allow long options

diff -r 29d32cd41d80 -r aa37514c9500 src/augparse.c
--- a/src/augparse.c	Sat Sep 06 15:25:57 2008 +0200
+++ b/src/augparse.c	Mon Sep 08 16:30:36 2008 -0700
@@ -22,6 +22,7 @@
 
 #include <config.h>
 #include <argz.h>
+#include <getopt.h>
 
 #include "list.h"
 #include "syntax.h"
@@ -34,7 +35,7 @@
     fprintf(stderr, "Usage: %s [OPTIONS] MODULE\n", progname);
     fprintf(stderr, "Evaluate MODULE. Generally, MODULE should contain unit tests.\n");
     fprintf(stderr, "\nOptions:\n\n");
-    fprintf(stderr, "  -I DIR        Add DIR to the module loadpath. Can be given multiple times.\n");
+    fprintf(stderr, "  -I, --include DIR  search DIR for modules; can be given mutiple times\n");
     exit(EXIT_FAILURE);
 }
 
@@ -43,10 +44,16 @@
     struct augeas *aug;
     char *loadpath = NULL;
     size_t loadpathlen = 0;
+    struct option options[] = {
+        { "help",      0, 0, 'h' },
+        { "include",   1, 0, 'I' },
+        { 0, 0, 0, 0}
+    };
+    int idx;
 
     progname = argv[0];
 
-    while ((opt = getopt(argc, argv, "hI:")) != -1) {
+    while ((opt = getopt_long(argc, argv, "hI:", options, &idx)) != -1) {
         switch(opt) {
         case 'I':
             argz_add(&loadpath, &loadpathlen, optarg);
diff -r 29d32cd41d80 -r aa37514c9500 src/augtool.c
--- a/src/augtool.c	Sat Sep 06 15:25:57 2008 +0200
+++ b/src/augtool.c	Mon Sep 08 16:30:36 2008 -0700
@@ -27,6 +27,7 @@
 #include <readline/readline.h>
 #include <readline/history.h>
 #include <argz.h>
+#include <getopt.h>
 
 struct command {
     const char *name;
@@ -478,23 +479,31 @@
     fprintf(stderr, "Run '%s help' to get a list of possible commands.\n",
             progname);
     fprintf(stderr, "\nOptions:\n\n");
-    fprintf(stderr, "  -c            Typecheck lenses. This can be very slow, and is therefore not\n"
-                    "                done by default, but is highly recommended during development.\n");
-    fprintf(stderr, "  -b            When files are changed, preserve the originals in a file\n"
-                    "                with extension '.augsave'\n");
-    fprintf(stderr, "  -n            Save changes in files with extension '.augnew', do not modify\n"
-                    "                the original files\n");
-    fprintf(stderr, "  -r ROOT       Use directory ROOT as the root of the filesystem.  Takes precedence\n"
-                    "                over a root set with the AUGEAS_ROOT environment variable.\n");
-    fprintf(stderr, "  -I DIR        Add DIR to the module loadpath. Can be given multiple times.\n");
+    fprintf(stderr, "  -c, --typecheck    typecheck lenses\n");
+    fprintf(stderr, "  -b, --backup       preserve originals of modified files with\n"
+                    "                     extension '.augsave'\n");
+    fprintf(stderr, "  -n, --new          save changes in files with extension '.augnew',\n"
+                    "                     leave original unchanged\n");
+    fprintf(stderr, "  -r, --root ROOT    use ROOT as the root of the filesystem\n");
+    fprintf(stderr, "  -I, --include DIR  search DIR for modules; can be given mutiple times\n");
     exit(EXIT_FAILURE);
 }
 
 static void parse_opts(int argc, char **argv) {
     int opt;
     size_t loadpathlen = 0;
+    struct option options[] = {
+        { "help",      0, 0, 'h' },
+        { "typecheck", 0, 0, 'c' },
+        { "backup",    0, 0, 'b' },
+        { "new",       0, 0, 'n' },
+        { "root",      1, 0, 'r' },
+        { "include",   1, 0, 'I' },
+        { 0, 0, 0, 0}
+    };
+    int idx;
 
-    while ((opt = getopt(argc, argv, "hnbcr:I:")) != -1) {
+    while ((opt = getopt_long(argc, argv, "hnbcr:I:", options, &idx)) != -1) {
         switch(opt) {
         case 'c':
             flags |= AUG_TYPE_CHECK;




More information about the augeas-devel mailing list