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

Method defaultCommand

src/CLI2.cpp:1791–1850  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Look for situations that require defaults: 1. If no command was found, and no ID/UUID, and if rc.default.command is configured, inject the lexed tokens from rc.default.command. 2. If no command was found, but an ID/UUID was found, then assume a command of 'information'.

Source from the content-addressed store, hash-verified

1789// of 'information'.
1790//
1791void CLI2::defaultCommand() {
1792 // Scan the top-level branches for evidence of ID, UUID, overrides and other
1793 // arguments.
1794 bool changes = false;
1795 bool found_command = false;
1796 bool found_sequence = false;
1797
1798 for (const auto& a : _args) {
1799 std::string raw = a.attribute("raw");
1800
1801 if (a.hasTag("CMD")) found_command = true;
1802
1803 if (a._lextype == Lexer::Type::uuid || a._lextype == Lexer::Type::number) found_sequence = true;
1804 }
1805
1806 // If no command was specified, then a command will be inserted.
1807 if (!found_command) {
1808 // Default command.
1809 if (!found_sequence) {
1810 // Apply overrides, if any.
1811 std::string defaultCommand = Context::getContext().config.get("default.command");
1812 if (defaultCommand != "") {
1813 // Modify _args, _original_args to be:
1814 // <args0> [<def0> ...] <args1> [...]
1815
1816 std::vector<A2> reconstructedOriginals{_original_args[0]};
1817 std::vector<A2> reconstructed{_args[0]};
1818
1819 std::string lexeme;
1820 Lexer::Type type;
1821 Lexer lex(defaultCommand);
1822
1823 while (lex.token(lexeme, type)) {
1824 reconstructedOriginals.emplace_back(lexeme, type);
1825
1826 A2 cmd(lexeme, type);
1827 cmd.tag("DEFAULT");
1828 reconstructed.push_back(cmd);
1829 }
1830
1831 for (unsigned int i = 1; i < _original_args.size(); ++i)
1832 reconstructedOriginals.push_back(_original_args[i]);
1833
1834 for (unsigned int i = 1; i < _args.size(); ++i) reconstructed.push_back(_args[i]);
1835
1836 _original_args = reconstructedOriginals;
1837 _args = reconstructed;
1838 changes = true;
1839 }
1840 } else {
1841 A2 info("information", Lexer::Type::word);
1842 info.tag("ASSUMED");
1843 _args.push_back(info);
1844 changes = true;
1845 }
1846 }
1847
1848 if (changes && Context::getContext().config.getInteger("debug.parser") >= 2)

Callers

nothing calls this directly

Calls 6

attributeMethod · 0.80
tokenMethod · 0.80
tagMethod · 0.80
hasTagMethod · 0.45
getMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected