mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
nix/main: Add AliasStatus::{Deprecated,AcceptedShorthand}
This commit is contained in:
parent
ef5c846e25
commit
98b85b2166
1 changed files with 42 additions and 26 deletions
|
@ -42,6 +42,19 @@ void chrootHelper(int argc, char * * argv);
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
enum struct AliasStatus {
|
||||||
|
/** Aliases that don't go away */
|
||||||
|
AcceptedShorthand,
|
||||||
|
/** Aliases that will go away */
|
||||||
|
Deprecated,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** An alias, except for the original syntax, which is in the map key. */
|
||||||
|
struct AliasInfo {
|
||||||
|
AliasStatus status;
|
||||||
|
std::vector<std::string> replacement;
|
||||||
|
};
|
||||||
|
|
||||||
/* Check if we have a non-loopback/link-local network interface. */
|
/* Check if we have a non-loopback/link-local network interface. */
|
||||||
static bool haveInternet()
|
static bool haveInternet()
|
||||||
{
|
{
|
||||||
|
@ -134,29 +147,29 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::vector<std::string>> aliases = {
|
std::map<std::string, AliasInfo> aliases = {
|
||||||
{"add-to-store", {"store", "add-path"}},
|
{"add-to-store", { AliasStatus::Deprecated, {"store", "add-path"}}},
|
||||||
{"cat-nar", {"nar", "cat"}},
|
{"cat-nar", { AliasStatus::Deprecated, {"nar", "cat"}}},
|
||||||
{"cat-store", {"store", "cat"}},
|
{"cat-store", { AliasStatus::Deprecated, {"store", "cat"}}},
|
||||||
{"copy-sigs", {"store", "copy-sigs"}},
|
{"copy-sigs", { AliasStatus::Deprecated, {"store", "copy-sigs"}}},
|
||||||
{"dev-shell", {"develop"}},
|
{"dev-shell", { AliasStatus::Deprecated, {"develop"}}},
|
||||||
{"diff-closures", {"store", "diff-closures"}},
|
{"diff-closures", { AliasStatus::Deprecated, {"store", "diff-closures"}}},
|
||||||
{"dump-path", {"store", "dump-path"}},
|
{"dump-path", { AliasStatus::Deprecated, {"store", "dump-path"}}},
|
||||||
{"hash-file", {"hash", "file"}},
|
{"hash-file", { AliasStatus::Deprecated, {"hash", "file"}}},
|
||||||
{"hash-path", {"hash", "path"}},
|
{"hash-path", { AliasStatus::Deprecated, {"hash", "path"}}},
|
||||||
{"ls-nar", {"nar", "ls"}},
|
{"ls-nar", { AliasStatus::Deprecated, {"nar", "ls"}}},
|
||||||
{"ls-store", {"store", "ls"}},
|
{"ls-store", { AliasStatus::Deprecated, {"store", "ls"}}},
|
||||||
{"make-content-addressable", {"store", "make-content-addressed"}},
|
{"make-content-addressable", { AliasStatus::Deprecated, {"store", "make-content-addressed"}}},
|
||||||
{"optimise-store", {"store", "optimise"}},
|
{"optimise-store", { AliasStatus::Deprecated, {"store", "optimise"}}},
|
||||||
{"ping-store", {"store", "ping"}},
|
{"ping-store", { AliasStatus::Deprecated, {"store", "ping"}}},
|
||||||
{"sign-paths", {"store", "sign"}},
|
{"sign-paths", { AliasStatus::Deprecated, {"store", "sign"}}},
|
||||||
{"show-derivation", {"derivation", "show"}},
|
{"show-derivation", { AliasStatus::Deprecated, {"derivation", "show"}}},
|
||||||
{"show-config", {"config", "show"}},
|
{"show-config", { AliasStatus::Deprecated, {"config", "show"}}},
|
||||||
{"to-base16", {"hash", "to-base16"}},
|
{"to-base16", { AliasStatus::Deprecated, {"hash", "to-base16"}}},
|
||||||
{"to-base32", {"hash", "to-base32"}},
|
{"to-base32", { AliasStatus::Deprecated, {"hash", "to-base32"}}},
|
||||||
{"to-base64", {"hash", "to-base64"}},
|
{"to-base64", { AliasStatus::Deprecated, {"hash", "to-base64"}}},
|
||||||
{"verify", {"store", "verify"}},
|
{"verify", { AliasStatus::Deprecated, {"store", "verify"}}},
|
||||||
{"doctor", {"config", "check"}},
|
{"doctor", { AliasStatus::Deprecated, {"config", "check"}}},
|
||||||
};
|
};
|
||||||
|
|
||||||
bool aliasUsed = false;
|
bool aliasUsed = false;
|
||||||
|
@ -167,10 +180,13 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
|
||||||
auto arg = *pos;
|
auto arg = *pos;
|
||||||
auto i = aliases.find(arg);
|
auto i = aliases.find(arg);
|
||||||
if (i == aliases.end()) return pos;
|
if (i == aliases.end()) return pos;
|
||||||
warn("'%s' is a deprecated alias for '%s'",
|
auto & info = i->second;
|
||||||
arg, concatStringsSep(" ", i->second));
|
if (info.status == AliasStatus::Deprecated) {
|
||||||
|
warn("'%s' is a deprecated alias for '%s'",
|
||||||
|
arg, concatStringsSep(" ", info.replacement));
|
||||||
|
}
|
||||||
pos = args.erase(pos);
|
pos = args.erase(pos);
|
||||||
for (auto j = i->second.rbegin(); j != i->second.rend(); ++j)
|
for (auto j = info.replacement.rbegin(); j != info.replacement.rend(); ++j)
|
||||||
pos = args.insert(pos, *j);
|
pos = args.insert(pos, *j);
|
||||||
aliasUsed = true;
|
aliasUsed = true;
|
||||||
return pos;
|
return pos;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue