1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-12 05:26:02 +01:00

Move alias support from NixArgs to MultiCommand

This allows subcommands to declare aliases, e.g. `nix store ping` is
now a proper alias of `nix store info`.
This commit is contained in:
Eelco Dolstra 2025-04-10 18:40:27 +02:00
parent 8443f01536
commit 666aa20da8
6 changed files with 75 additions and 73 deletions

View file

@ -647,4 +647,25 @@ nlohmann::json MultiCommand::toJSON()
return res;
}
Strings::iterator MultiCommand::rewriteArgs(Strings & args, Strings::iterator pos)
{
if (command)
return command->second->rewriteArgs(args, pos);
if (aliasUsed || pos == args.end()) return pos;
auto arg = *pos;
auto i = aliases.find(arg);
if (i == aliases.end()) return pos;
auto & info = i->second;
if (info.status == AliasStatus::Deprecated) {
warn("'%s' is a deprecated alias for '%s'",
arg, concatStringsSep(" ", info.replacement));
}
pos = args.erase(pos);
for (auto j = info.replacement.rbegin(); j != info.replacement.rend(); ++j)
pos = args.insert(pos, *j);
aliasUsed = true;
return pos;
}
}