diff --git a/src/tools/kdb/cmdline.cpp b/src/tools/kdb/cmdline.cpp index 90857d9ec8f..1c4d09d596e 100644 --- a/src/tools/kdb/cmdline.cpp +++ b/src/tools/kdb/cmdline.cpp @@ -563,6 +563,26 @@ kdb::Key Cmdline::createKey (int pos, bool allowCascading) const return root; } + +/** + * @brief return a parent key to use with kdbGet/kdbSet + * + * @param key the key of interest + * + * @return a newly created key to use with kdbGet/kdbSet. If -f was specified, a simple copy will be returned, otherwise a copy without a namespace will be returned. + */ +kdb::Key Cmdline::getParentKey (kdb::Key const & key) const +{ + if (force) + { + return key.dup (); + } + else + { + return removeNamespace (key); + } +} + /** * @brief resolve the bookmark with the given name * diff --git a/src/tools/kdb/cmdline.hpp b/src/tools/kdb/cmdline.hpp index 19ecccaf87a..6e0c23b6b6f 100644 --- a/src/tools/kdb/cmdline.hpp +++ b/src/tools/kdb/cmdline.hpp @@ -93,6 +93,7 @@ class Cmdline std::string profile; kdb::Key createKey (int pos, bool allowCascading = true) const; + kdb::Key getParentKey (kdb::Key const & key) const; kdb::Key resolveBookmark (std::string name) const; kdb::KeySet getPluginsConfig (std::string basepath = "user:/") const; diff --git a/src/tools/kdb/mergehelper.cpp b/src/tools/kdb/mergehelper.cpp index 19494020926..30610836c0e 100644 --- a/src/tools/kdb/mergehelper.cpp +++ b/src/tools/kdb/mergehelper.cpp @@ -143,6 +143,18 @@ Key prependNamespace (Key const & root, std::string const & ns) return ret; } +Key removeNamespace (Key const & root) +{ + Key ret = root.dup (); + if (!ret.isCascading ()) + { + string keyName = ret.getName (); + string cascadingName = keyName.substr (keyName.find(":") + 1); + ret.setName (cascadingName); + } + return ret; +} + void applyMeta (KeySet & imported, KeySet const & base) { for (auto k : imported) diff --git a/src/tools/kdb/mergehelper.hpp b/src/tools/kdb/mergehelper.hpp index 1b19f5fb3b6..477a61f8648 100644 --- a/src/tools/kdb/mergehelper.hpp +++ b/src/tools/kdb/mergehelper.hpp @@ -20,6 +20,7 @@ using namespace kdb::tools::merging; kdb::KeySet prependNamespace (kdb::KeySet const & resultKeys, std::string const & ns); kdb::Key prependNamespace (kdb::Key const & root, std::string const & ns); +kdb::Key removeNamespace (kdb::Key const & root); void applyMeta (kdb::KeySet & imported, kdb::KeySet const & base); class MergeHelper