summaryrefslogtreecommitdiff
path: root/src/cli_shell_api.cpp
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-12-02 14:35:25 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2010-12-02 14:35:25 -0800
commit352a9e94534933aca7403e91d1dc55c26bf633ce (patch)
treedf413a5fbd1ab0e0b4776eff98149dd9cbc8006d /src/cli_shell_api.cpp
parent58005829f825c3e6843d0c2c36e1e343194ec3dd (diff)
downloadvyatta-cfg-352a9e94534933aca7403e91d1dc55c26bf633ce.tar.gz
vyatta-cfg-352a9e94534933aca7403e91d1dc55c26bf633ce.zip
implement load function in new config input/output infrastructure.
* add "commands diff" functionality to config input/output infrastructure. * consolidate similar logic in "commands diff" and "show diff". * add loadFile functionality to cstore using "commands diff". * export loadFile through shell API.
Diffstat (limited to 'src/cli_shell_api.cpp')
-rw-r--r--src/cli_shell_api.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/cli_shell_api.cpp b/src/cli_shell_api.cpp
index af0a320..b9b8188 100644
--- a/src/cli_shell_api.cpp
+++ b/src/cli_shell_api.cpp
@@ -24,6 +24,7 @@
#include <cstore/unionfs/cstore-unionfs.hpp>
#include <cnode/cnode.hpp>
#include <cnode/cnode-algorithm.hpp>
+#include <cparse/cparse.hpp>
/* This program provides an API for shell scripts (e.g., snippets in
* templates, standalone scripts, etc.) to access the CLI cstore library.
@@ -405,18 +406,27 @@ showCfg(const vector<string>& args)
cnode::CfgNode aroot(cstore, nargs, true, true);
if (active_only) {
- // just show the active config
- cnode::show_diff(aroot, aroot, op_show_show_defaults,
- op_show_hide_secrets);
- } else if (working_only) {
- // just show the working config without diff markers
- cnode::CfgNode wroot(cstore, nargs, false, true);
- cnode::show_diff(wroot, wroot, op_show_show_defaults,
- op_show_hide_secrets);
+ // just show the active config (no diff)
+ cnode::show_cfg(aroot, op_show_show_defaults, op_show_hide_secrets);
} else {
cnode::CfgNode wroot(cstore, nargs, false, true);
- cnode::show_diff(aroot, wroot, op_show_show_defaults,
- op_show_hide_secrets);
+ if (working_only) {
+ // just show the working config (no diff)
+ cnode::show_cfg(wroot, op_show_show_defaults, op_show_hide_secrets);
+ } else {
+ cnode::show_cfg_diff(aroot, wroot, op_show_show_defaults,
+ op_show_hide_secrets);
+ }
+ }
+}
+
+static void
+loadFile(const vector<string>& args)
+{
+ UnionfsCstore cstore(true);
+ if (!cstore.loadFile(args[0].c_str())) {
+ // loadFile failed
+ exit(1);
}
}
@@ -463,6 +473,7 @@ static OpT ops[] = {
OP(validateTmplValPath, -1, NULL, 1, "Must specify config path"),
OP(showCfg, -1, NULL, -1, NULL),
+ OP(loadFile, 1, "Must specify config file", -1, NULL),
{NULL, -1, NULL, -1, NULL, NULL}
};