[augeas-devel] [PATCH] Add clearm command to augtool

francis.giraldeau at usherbrooke.ca francis.giraldeau at usherbrooke.ca
Tue Oct 26 14:57:57 UTC 2010


From: Francis Giraldeau <francis.giraldeau at gmail.com>

The clearm command is the same as setm, but sets the node value to
NULL in place of a string, suitable in some use case.

Fix ticket #146
---
 src/augtool.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/src/augtool.c b/src/augtool.c
index 6c8416a..303e765 100644
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -624,6 +624,36 @@ static const struct command_def cmd_setm_def = {
     "BASE will be modified."
 };
 
+static void cmd_clearm(struct command *cmd) {
+    const char *base = arg_value(cmd, "base");
+    const char *sub  = arg_value(cmd, "sub");
+    int r;
+
+    r = aug_setm(aug, base, sub, NULL);
+    err_check(cmd);
+    if (r == -1)
+        printf ("Failed\n");
+}
+
+static const struct command_opt_def cmd_clearm_opts[] = {
+    { .type = CMD_PATH, .name = "base", .optional = false,
+      .help = "the base node" },
+    { .type = CMD_PATH, .name = "sub", .optional = false,
+      .help = "the subtree relative to the base" },
+    CMD_OPT_DEF_LAST
+};
+
+static const struct command_def cmd_clearm_def = {
+    .name = "clearm",
+    .opts = cmd_clearm_opts,
+    .handler = cmd_clearm,
+    .synopsis = "clear the value of multiple nodes",
+    .help = "Clear multiple nodes values in one operation. Find or create a"
+    " node matching SUB\n by interpreting SUB as a path expression relative"
+    " to each node matching\n BASE. If SUB is '.', the nodes matching "
+    "BASE will be modified."
+};
+
 static void cmd_defvar(struct command *cmd) {
     const char *name = arg_value(cmd, "name");
     const char *path = arg_value(cmd, "expr");
@@ -932,6 +962,7 @@ static const struct command_def const *commands[] = {
     &cmd_save_def,
     &cmd_set_def,
     &cmd_setm_def,
+    &cmd_clearm_def,
     &cmd_help_def,
     &cmd_def_last
 };
-- 
1.7.1




More information about the augeas-devel mailing list