aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-06-04 13:16:28 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-06-04 13:16:28 +0200
commitf85606c431dc1225ba32ecefaa4aea1eb6d4356e (patch)
treec11a7261d8b58bc1528e1b221a741353d6a4a04a /src/libutil
parent81cafda306e7257d0d77a20b9bde45049abaa52a (diff)
parent0f44b60e6dc999697bf9f2a4b3652a0551016598 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/args.cc4
-rw-r--r--src/libutil/args.hh2
-rw-r--r--src/libutil/util.hh3
3 files changed, 7 insertions, 2 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc
index 8667bd450..24b8ca66b 100644
--- a/src/libutil/args.cc
+++ b/src/libutil/args.cc
@@ -303,6 +303,10 @@ MultiCommand::MultiCommand(const Commands & commands)
.optional = true,
.handler = {[=](std::string s) {
assert(!command);
+ if (auto alias = get(deprecatedAliases, s)) {
+ warn("'%s' is a deprecated alias for '%s'", s, *alias);
+ s = *alias;
+ }
if (auto prefix = needsCompletion(s)) {
for (auto & [name, command] : commands)
if (hasPrefix(name, *prefix))
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index 405ec3d47..59541df99 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -248,6 +248,8 @@ public:
std::map<Command::Category, std::string> categories;
+ std::map<std::string, std::string> deprecatedAliases;
+
// Selected command, if any.
std::optional<std::pair<std::string, ref<Command>>> command;
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 52ca804a0..194a3ed4a 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -463,8 +463,7 @@ string base64Encode(const string & s);
string base64Decode(const string & s);
-/* Get a value for the specified key from an associate container, or a
- default value if the key doesn't exist. */
+/* Get a value for the specified key from an associate container. */
template <class T>
std::optional<typename T::mapped_type> get(const T & map, const typename T::key_type & key)
{