aboutsummaryrefslogtreecommitdiff
path: root/src/nix/command.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/command.cc')
-rw-r--r--src/nix/command.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 9a38c77f1..596217775 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -11,7 +11,21 @@ extern char * * environ __attribute__((weak));
namespace nix {
-Commands * RegisterCommand::commands = nullptr;
+RegisterCommand::Commands * RegisterCommand::commands = nullptr;
+
+nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
+{
+ nix::Commands res;
+ for (auto & [name, command] : *RegisterCommand::commands)
+ if (name.size() == prefix.size() + 1) {
+ bool equal = true;
+ for (size_t i = 0; i < prefix.size(); ++i)
+ if (name[i] != prefix[i]) equal = false;
+ if (equal)
+ res.insert_or_assign(name[prefix.size()], command);
+ }
+ return res;
+}
void NixMultiCommand::printHelp(const string & programName, std::ostream & out)
{