diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-03-07 19:47:45 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-03-07 19:47:45 +0100 |
commit | 30ddd37873a7ce0e6a8c884e03c6ebc52ea816a6 (patch) | |
tree | 28bd8f3fe7ef3d17d5cb38a9c0c64ac1b81891d0 /src/libutil/args.cc | |
parent | 60a68a4fee05f0dd510afcd393463e847e3c4488 (diff) | |
parent | dcf4f77fac8bc214afd4851b367ce386f0a34658 (diff) |
Merge branch 'cli-suggestions' of https://github.com/thufschmitt/nix
Diffstat (limited to 'src/libutil/args.cc')
-rw-r--r-- | src/libutil/args.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index f970c0e9e..69aa0d094 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -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; }} |