Imported Upstream version 1.6.0
[platform/upstream/augeas.git] / src / augrun.c
index b5a84d1..ce4bbc0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * augrun.c: command interpreter for augeas
  *
- * Copyright (C) 2011 David Lutterkort
+ * Copyright (C) 2011-2015 David Lutterkort
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1010,6 +1010,33 @@ static const struct command_def cmd_transform_def = {
     .help = cmd_transform_help
 };
 
+static void cmd_load_file(struct command *cmd) {
+    const char *file = arg_value(cmd, "file");
+    int r = 0;
+
+    r = aug_load_file(cmd->aug, file);
+    if (r < 0)
+      ERR_REPORT(cmd, AUG_ECMDRUN,
+          "Failed to load file %s", file);
+}
+
+static const struct command_opt_def cmd_load_file_opts[] = {
+    { .type = CMD_PATH, .name = "file", .optional = false,
+      .help = "the file to load" },
+    CMD_OPT_DEF_LAST
+};
+
+static const char const cmd_load_file_help[] =
+    "Load a specific FILE, using autoload statements.\n";
+
+static const struct command_def cmd_load_file_def = {
+    .name = "load-file",
+    .opts = cmd_load_file_opts,
+    .handler = cmd_load_file,
+    .synopsis = "load a specific file",
+    .help = cmd_load_file_help
+};
+
 static void cmd_save(struct command *cmd) {
     int r;
     r = aug_save(cmd->aug);
@@ -1225,6 +1252,7 @@ static void cmd_errors(struct command *cmd) {
         const char *last     = err_get(aug, match, "lens/last_matched");
         const char *next     = err_get(aug, match, "lens/next_not_matched");
         const char *msg      = err_get(aug, match, "message");
+        const char *path     = err_get(aug, match, "path");
         const char *kind     = NULL;
 
         aug_get(aug, match, &kind);
@@ -1239,6 +1267,8 @@ static void cmd_errors(struct command *cmd) {
         if (line != NULL) {
             fprintf(cmd->out, "Error in %s:%s.%s (%s)\n",
                     filename, line, char_pos, kind);
+        } else if (path != NULL) {
+            fprintf(cmd->out, "Error in %s at node %s (%s)\n", filename, path, kind);
         } else {
             fprintf(cmd->out, "Error in %s (%s)\n", filename, kind);
         }
@@ -1294,6 +1324,7 @@ static const struct command_grp_def cmd_grp_admin_def = {
         &cmd_save_def,
         &cmd_store_def,
         &cmd_transform_def,
+        &cmd_load_file_def,
         &cmd_def_last
     }
 };