mirror of
https://github.com/NixOS/nix
synced 2025-06-28 13:41:15 +02:00
Implement a suggestions mechanism
Each `Error` class now includes a set of suggestions, and these are printed by the top-level handler.
This commit is contained in:
parent
b09baf690b
commit
c0792b1546
7 changed files with 191 additions and 6 deletions
|
@ -328,8 +328,13 @@ MultiCommand::MultiCommand(const Commands & commands_)
|
|||
completions->add(name);
|
||||
}
|
||||
auto i = commands.find(s);
|
||||
if (i == commands.end())
|
||||
throw UsageError("'%s' is not a recognised command", s);
|
||||
if (i == commands.end()) {
|
||||
std::set<std::string> commandNames;
|
||||
for (auto & [name, _] : commands)
|
||||
commandNames.insert(name);
|
||||
auto suggestions = Suggestions::bestMatches(commandNames, s);
|
||||
throw UsageError(suggestions, "'%s' is not a recognised command", s);
|
||||
}
|
||||
command = {s, i->second()};
|
||||
command->second->parent = this;
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue