aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-03 22:45:44 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-03 22:45:44 +0100
commitaf373c2ece2c14ac652313a6f370dc344c85f86e (patch)
treeeb6318cedfc19d16d6a3bc2f3a85fcfaebe3935c /src/nix
parent0c15ae5d4b3366a14bca885e02599a941a334920 (diff)
Add deprecated aliases for renamed commands
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/main.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 6d8c66406..94f4cad3c 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -112,8 +112,36 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
.description = "consider all previously downloaded files out-of-date",
.handler = {[&]() { refresh = true; }},
});
+ }
- deprecatedAliases.insert({"dev-shell", "develop"});
+ std::map<std::string, std::vector<std::string>> aliases = {
+ {"dev-shell", {"develop"}},
+ {"hash-file", {"hash", "file"}},
+ {"hash-path", {"hash", "path"}},
+ {"to-base16", {"hash", "to-base16"}},
+ {"to-base32", {"hash", "to-base32"}},
+ {"to-base64", {"hash", "to-base64"}},
+ {"ls-nar", {"nar", "ls"}},
+ {"ls-store", {"store", "ls"}},
+ {"cat-nar", {"nar", "cat"}},
+ {"cat-store", {"store", "cat"}},
+ };
+
+ bool aliasUsed = false;
+
+ Strings::iterator rewriteArgs(Strings & args, Strings::iterator pos) override
+ {
+ if (aliasUsed || command || pos == args.end()) return pos;
+ auto arg = *pos;
+ auto i = aliases.find(arg);
+ if (i == aliases.end()) return pos;
+ warn("'%s' is a deprecated alias for '%s'",
+ arg, concatStringsSep(" ", i->second));
+ pos = args.erase(pos);
+ for (auto j = i->second.rbegin(); j != i->second.rend(); ++j)
+ pos = args.insert(pos, *j);
+ aliasUsed = true;
+ return pos;
}
void printFlags(std::ostream & out) override