Skip to content

Commit

Permalink
implement ElektraInitiative#2561 for kdb set
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2718 committed Aug 25, 2021
1 parent a888a13 commit 39b70d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/tools/kdb/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ())
{
Expand Down
9 changes: 5 additions & 4 deletions src/tools/kdb/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '/';

Expand Down Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/kdb/set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SetCommand : public Command

virtual std::string getShortOptions () override
{
return "qN";
return "qNf";
}

virtual std::string getSynopsis () override
Expand Down

0 comments on commit 39b70d6

Please sign in to comment.