MCPcopy Create free account
hub / github.com/daniele77/cli / HandleCommand

Method HandleCommand

include/cli/cli.h:654–678  ·  view source on GitHub ↗

* Handles a command from the user input. * * This function checks if the first element of the `cmdLine` vector matches any of the * valid commands listed in `cmdNames`. If it does, it performs the following actions: * - If the `cmdLine` is of length 1 (only the command itself), it sets the current * session to this object (`session.Current(this)`)

Source from the content-addressed store, hash-verified

652 * @return true if the command is handled successfully, false otherwise.
653 */
654 bool HandleCommand(const std::vector<std::string>& cmdNames, const std::vector<std::string>& cmdLine, CliSession& session)
655 {
656 if (!IsEnabled())
657 return false;
658
659 assert(!cmdLine.empty());
660
661 if (std::find(cmdNames.begin(), cmdNames.end(), cmdLine[0]) != cmdNames.end())
662 {
663 if (cmdLine.size() == 1)
664 {
665 session.Current(this);
666 return true;
667 }
668 else
669 {
670 // check also for subcommands
671 std::vector<std::string > subCmdLine(cmdLine.begin()+1, cmdLine.end());
672 for (auto& cmd: *cmds)
673 if (cmd->Exec( subCmdLine, session )) return true;
674 return (parent && parent->ExecParent(subCmdLine, session));
675 }
676 }
677 return false;
678 }
679
680 static std::string ParentShortcut()
681 {

Callers

nothing calls this directly

Calls 3

CurrentMethod · 0.80
ExecParentMethod · 0.80
ExecMethod · 0.45

Tested by

no test coverage detected