[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] [PATCH 09/10] Expose aug_text_retrieve in augtool and aug_srun



From: David Lutterkort <lutter redhat com>

---
 src/augrun.c  |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/augtool.c |    2 +-
 2 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/src/augrun.c b/src/augrun.c
index f758b59..9b4b31f 100644
--- a/src/augrun.c
+++ b/src/augrun.c
@@ -1043,6 +1043,47 @@ static const struct command_def cmd_store_def = {
     .help = cmd_store_help
 };
 
+static void cmd_retrieve(struct command *cmd) {
+    const char *lens = arg_value(cmd, "lens");
+    const char *path = arg_value(cmd, "path");
+    const char *text_in = arg_value(cmd, "text");
+    char *text_out;
+    unsigned int text_out_len;
+
+    aug_text_retrieve(cmd->aug, lens, path, text_in, strlen(text_in),
+                      &text_out, &text_out_len);
+    ERR_BAIL(cmd->aug);
+
+    if (text_out != NULL)
+        fprintf(cmd->out, "%s\n", text_out);
+ error:
+    free(text_out);
+    return;
+}
+
+static const struct command_opt_def cmd_retrieve_opts[] = {
+    { .type = CMD_STR, .name = "lens", .optional = false,
+      .help = "the name of the lens" },
+    { .type = CMD_PATH, .name = "path", .optional = false,
+      .help = "where to retrieve parsed text" },
+    { .type = CMD_STR, .name = "text", .optional = false,
+      .help = "the text to parse" },
+    CMD_OPT_DEF_LAST
+};
+
+static const char const cmd_retrieve_help[] =
+    "Transform tree at PATH back into text using lens LENS and print the\n"
+    " resulting text. Assume that the tree was initially read in with the\n"
+    " same lens and TEXT as input.";
+
+static const struct command_def cmd_retrieve_def = {
+    .name = "retrieve",
+    .opts = cmd_retrieve_opts,
+    .handler = cmd_retrieve,
+    .synopsis = "transform tree into text",
+    .help = cmd_retrieve_help
+};
+
 static const struct command_def const *commands[] = {
     &cmd_quit_def,
     &cmd_clear_def,
@@ -1065,6 +1106,7 @@ static const struct command_def const *commands[] = {
     &cmd_clearm_def,
     &cmd_span_def,
     &cmd_store_def,
+    &cmd_retrieve_def,
     &cmd_touch_def,
     &cmd_help_def,
     &cmd_def_last
diff --git a/src/augtool.c b/src/augtool.c
index b4f7cc8..7283735 100644
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -168,7 +168,7 @@ static char *readline_command_generator(const char *text, int state) {
         "quit", "clear", "defnode", "defvar",
         "get", "ins", "load", "ls", "match",
         "mv", "print", "dump-xml", "rm", "save", "set", "setm",
-        "clearm", "span", "store", "help", NULL };
+        "clearm", "span", "store", "retrieve", "help", NULL };
 
     static int current = 0;
     const char *name;
-- 
1.7.7.6



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]