MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / findCommand

Method findCommand

src/CLI2.cpp:986–1025  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Scan all arguments and if any are an exact match for a command name, then tag as CMD. If an argument is an exact match for an attribute, despite being an inexact match for a command, then it is not a command.

Source from the content-addressed store, hash-verified

984// tag as CMD. If an argument is an exact match for an attribute, despite being
985// an inexact match for a command, then it is not a command.
986bool CLI2::findCommand() {
987 for (auto& a : _args) {
988 std::string raw = a.attribute("raw");
989 std::string canonical;
990
991 // If the arg canonicalized to a 'cmd', but is also not an exact match
992 // for an 'attribute', proceed. Example:
993 // task project=foo list
994 // ^cmd ^cmd
995 // ^attribute
996 if (exactMatch("cmd", raw))
997 canonical = raw;
998 else if (exactMatch("attribute", raw))
999 continue;
1000 else if (!canonicalize(canonical, "cmd", raw))
1001 continue;
1002
1003 a.attribute("canonical", canonical);
1004 a.tag("CMD");
1005
1006 // Apply command DNA as tags.
1007 Command* command = Context::getContext().commands[canonical];
1008 if (command->read_only()) a.tag("READONLY");
1009 if (command->displays_id()) a.tag("SHOWSID");
1010 if (command->needs_gc()) a.tag("RUNSGC");
1011 if (command->uses_context()) a.tag("USESCONTEXT");
1012 if (command->accepts_filter()) a.tag("ALLOWSFILTER");
1013 if (command->accepts_modifications()) a.tag("ALLOWSMODIFICATIONS");
1014 if (command->accepts_miscellaneous()) a.tag("ALLOWSMISC");
1015
1016 if (Context::getContext().config.getInteger("debug.parser") >= 2)
1017 Context::getContext().debug(dump("CLI2::analyze findCommand"));
1018
1019 // Stop and indicate command found.
1020 return true;
1021 }
1022
1023 // Indicate command not found.
1024 return false;
1025}
1026
1027////////////////////////////////////////////////////////////////////////////////
1028// Search for exact 'value' in _entities category.

Callers

nothing calls this directly

Calls 10

attributeMethod · 0.80
tagMethod · 0.80
read_onlyMethod · 0.80
displays_idMethod · 0.80
needs_gcMethod · 0.80
accepts_filterMethod · 0.80
accepts_modificationsMethod · 0.80
accepts_miscellaneousMethod · 0.80
uses_contextMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected