diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli_shell_api.cpp | 7 | ||||
-rw-r--r-- | src/cnode/cnode-algorithm.cpp | 24 | ||||
-rw-r--r-- | src/cnode/cnode-algorithm.hpp | 12 | ||||
-rw-r--r-- | src/vyos-errors.h | 4 |
4 files changed, 30 insertions, 17 deletions
diff --git a/src/cli_shell_api.cpp b/src/cli_shell_api.cpp index 0439ccf..5766857 100644 --- a/src/cli_shell_api.cpp +++ b/src/cli_shell_api.cpp @@ -31,6 +31,8 @@ using namespace cstore; +int exit_code = 0; + /* This program provides an API for shell scripts (e.g., snippets in * templates, standalone scripts, etc.) to access the CLI cstore library. * It is installed in "/opt/vyatta/sbin", but a symlink "/bin/cli-shell-api" @@ -537,9 +539,10 @@ showConfig(Cstore& cstore, const Cpath& args) // default } - cnode::showConfig(cfg1, cfg2, args, op_show_show_defaults, + int res = cnode::showConfig(cfg1, cfg2, args, op_show_show_defaults, op_show_hide_secrets, op_show_context_diff, op_show_commands, op_show_ignore_edit); + exit_code = res; } static void @@ -765,7 +768,7 @@ main(int argc, char **argv) Cstore *cstore = Cstore::createCstore(OP_use_edit); OP_func(*cstore, args); delete cstore; - exit(0); + exit(exit_code); } diff --git a/src/cnode/cnode-algorithm.cpp b/src/cnode/cnode-algorithm.cpp index 379fb6a..7463534 100644 --- a/src/cnode/cnode-algorithm.cpp +++ b/src/cnode/cnode-algorithm.cpp @@ -24,6 +24,8 @@ #include <cparse/cparse.hpp> #include <cnode/cnode-algorithm.hpp> +#include <vyos-errors.h> + using namespace cnode; using namespace cstore; using namespace std; @@ -851,31 +853,33 @@ _print_cmds_list(const char *op, vector<Cpath>& list) } ////// algorithms -void +int cnode::show_cfg_diff(const CfgNode& cfg1, const CfgNode& cfg2, Cpath& cur_path, bool show_def, bool hide_secret, bool context_diff) { if (cfg1.isInvalid() || cfg2.isInvalid()) { printf("Specified configuration path is not valid\n"); - return; + return VYOS_INVALID_PATH; } if ((cfg1.isEmpty() && cfg2.isEmpty()) || (!cfg1.exists() && !cfg2.exists())) { printf("Configuration under specified path is empty\n"); - return; + return VYOS_EMPTY_CONFIG; } // use an invalid value for initial last_ctx Cpath last_ctx; _show_diff(&cfg1, &cfg2, -1, cur_path, last_ctx, show_def, hide_secret, context_diff); + return VYOS_SUCCESS; } -void +int cnode::show_cfg(const CfgNode& cfg, bool show_def, bool hide_secret) { Cpath cur_path; - show_cfg_diff(cfg, cfg, cur_path, show_def, hide_secret); + int res = show_cfg_diff(cfg, cfg, cur_path, show_def, hide_secret); + return res; } void @@ -916,7 +920,7 @@ cnode::get_cmds(const CfgNode& cfg, vector<Cpath>& set_list, _get_cmds_diff(&cfg, &cfg, cur_path, del_list, set_list, com_list); } -void +int cnode::showConfig(const string& cfg1, const string& cfg2, const Cpath& path, bool show_def, bool hide_secret, bool context_diff, bool show_cmds, bool ignore_edit) @@ -960,14 +964,16 @@ cnode::showConfig(const string& cfg1, const string& cfg2, } if (!croot1.get() || !croot2.get()) { printf("Cannot parse specified config file(s)\n"); - return; + return 1; } if (show_cmds) { show_cmds_diff(*croot1, *croot2); + return 0; } else { - show_cfg_diff(*croot1, *croot2, cur_path, show_def, hide_secret, - context_diff); + int res = show_cfg_diff(*croot1, *croot2, cur_path, show_def, hide_secret, + context_diff); + return res; } } diff --git a/src/cnode/cnode-algorithm.hpp b/src/cnode/cnode-algorithm.hpp index d17204f..3ab2992 100644 --- a/src/cnode/cnode-algorithm.hpp +++ b/src/cnode/cnode-algorithm.hpp @@ -43,10 +43,10 @@ void cmp_non_leaf_nodes(const CfgNode *cfg1, const CfgNode *cfg2, bool& is_leaf_typeless, std::string& name, std::string& value); -void show_cfg_diff(const CfgNode& cfg1, const CfgNode& cfg2, +int show_cfg_diff(const CfgNode& cfg1, const CfgNode& cfg2, cstore::Cpath& cur_path, bool show_def = false, bool hide_secret = false, bool context_diff = false); -void show_cfg(const CfgNode& cfg, bool show_def = false, +int show_cfg(const CfgNode& cfg, bool show_def = false, bool hide_secret = false); void show_cmds_diff(const CfgNode& cfg1, const CfgNode& cfg2); @@ -62,10 +62,10 @@ void get_cmds(const CfgNode& cfg, std::vector<cstore::Cpath>& set_list, extern const std::string ACTIVE_CFG; extern const std::string WORKING_CFG; -void showConfig(const std::string& cfg1, const std::string& cfg2, - const cstore::Cpath& path, bool show_def = false, - bool hide_secret = false, bool context_diff = false, - bool show_cmds = false, bool ignore_edit = false); +int showConfig(const std::string& cfg1, const std::string& cfg2, + const cstore::Cpath& path, bool show_def = false, + bool hide_secret = false, bool context_diff = false, + bool show_cmds = false, bool ignore_edit = false); /* these functions provide the functionality necessary for the "config * file" shell API. basically the API uses the "cparse" interface to diff --git a/src/vyos-errors.h b/src/vyos-errors.h new file mode 100644 index 0000000..790f4c4 --- /dev/null +++ b/src/vyos-errors.h @@ -0,0 +1,4 @@ +#define VYOS_SUCCESS 0 +#define VYOS_GENERAL_FAILURE 1 +#define VYOS_INVALID_PATH 2 +#define VYOS_EMPTY_CONFIG 3 |