From 8be946f8ecc49ca0908ba6e0b969b6adcf1537eb Mon Sep 17 00:00:00 2001 From: Alexander Firbas Date: Thu, 12 Aug 2021 14:11:21 +0200 Subject: [PATCH] implement #2561 for kdb set --- src/tools/kdb/cmdline.cpp | 4 ++++ src/tools/kdb/set.cpp | 9 +++++---- src/tools/kdb/set.hpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tools/kdb/cmdline.cpp b/src/tools/kdb/cmdline.cpp index 1c4d09d596e..145ceb45fe7 100644 --- a/src/tools/kdb/cmdline.cpp +++ b/src/tools/kdb/cmdline.cpp @@ -544,6 +544,10 @@ kdb::Key Cmdline::createKey (int pos, bool allowCascading) const { root = prependNamespace (root, ns); } + else if (!root.isCascading () && !ns.empty ()) + { + throw invalid_argument ("Cannot use the -N option with a key that already has a namespace."); + } if (!root.isValid ()) { diff --git a/src/tools/kdb/set.cpp b/src/tools/kdb/set.cpp index 75d0fd7de83..24dacc1ee36 100644 --- a/src/tools/kdb/set.cpp +++ b/src/tools/kdb/set.cpp @@ -34,11 +34,12 @@ int SetCommand::execute (Cmdline const & cl) KeySet conf; Key k = cl.createKey (0); std::string name = k.getName (); + Key parentKey = cl.getParentKey (k); // do not resume on any get errors // otherwise the user might break // the config - kdb.get (conf, k); + kdb.get (conf, parentKey); bool cascadingWrite = name[0] == '/'; @@ -70,9 +71,9 @@ int SetCommand::execute (Cmdline const & cl) toprint << "Set string to \"" << value << '"' << endl; key.setString (value); } - kdb.set (conf, k); - printWarnings (cerr, k, cl.verbose, cl.debug); - printError (cerr, k, cl.verbose, cl.debug); + kdb.set (conf, parentKey); + printWarnings (cerr, parentKey, cl.verbose, cl.debug); + printError (cerr, parentKey, cl.verbose, cl.debug); if (cascadingWrite) toprint << "Using name " << key.getName () << std::endl; if (!cl.quiet) cout << toprint.str (); diff --git a/src/tools/kdb/set.hpp b/src/tools/kdb/set.hpp index 90f72f2e818..44df83a4cf1 100644 --- a/src/tools/kdb/set.hpp +++ b/src/tools/kdb/set.hpp @@ -23,7 +23,7 @@ class SetCommand : public Command virtual std::string getShortOptions () override { - return "qN"; + return "qNf"; } virtual std::string getSynopsis () override