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

Method aliasExpansion

src/CLI2.cpp:742–798  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// If any aliases are found in un-TERMINATED arguments, replace the alias with a set of Lexed tokens from the configuration.

Source from the content-addressed store, hash-verified

740// If any aliases are found in un-TERMINATED arguments, replace the alias with
741// a set of Lexed tokens from the configuration.
742void CLI2::aliasExpansion() {
743 bool changes = false;
744 bool action;
745 int counter = 0;
746 do {
747 action = false;
748 std::vector<A2> reconstructed;
749
750 std::string raw;
751 for (const auto& i : _args) {
752 raw = i.attribute("raw");
753 if (i.hasTag("TERMINATED")) {
754 reconstructed.push_back(i);
755 } else if (_aliases.find(raw) != _aliases.end()) {
756 std::string lexeme;
757 Lexer::Type type;
758 Lexer lex(_aliases[raw]);
759 while (lex.token(lexeme, type)) reconstructed.emplace_back(lexeme, type);
760
761 action = true;
762 changes = true;
763 } else {
764 reconstructed.push_back(i);
765 }
766 }
767
768 _args = reconstructed;
769
770 std::vector<A2> reconstructedOriginals;
771 bool terminated = false;
772 for (const auto& i : _original_args) {
773 if (i.attribute("raw") == "--") terminated = true;
774
775 if (terminated) {
776 reconstructedOriginals.push_back(i);
777 } else if (_aliases.find(i.attribute("raw")) != _aliases.end()) {
778 std::string lexeme;
779 Lexer::Type type;
780 Lexer lex(_aliases[i.attribute("raw")]);
781 while (lex.token(lexeme, type)) reconstructedOriginals.emplace_back(lexeme, type);
782
783 action = true;
784 changes = true;
785 } else {
786 reconstructedOriginals.push_back(i);
787 }
788 }
789
790 _original_args = reconstructedOriginals;
791 } while (action && counter++ < safetyValveDefault);
792
793 if (counter >= safetyValveDefault)
794 Context::getContext().debug(format("Nested alias limit of {1} reached.", safetyValveDefault));
795
796 if (changes && Context::getContext().config.getInteger("debug.parser") >= 2)
797 Context::getContext().debug(dump("CLI2::analyze aliasExpansion"));
798}
799

Callers

nothing calls this directly

Calls 5

attributeMethod · 0.80
findMethod · 0.80
tokenMethod · 0.80
hasTagMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected