From 294e68a3f6287ffd0abdc584af65ba6a5e480285 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 5 Dec 2025 12:57:19 +0100 Subject: [PATCH 1/2] Rename AttrPath -> AttrSelectionPath --- src/libexpr/eval.cc | 6 ++--- src/libexpr/include/nix/expr/nixexpr.hh | 4 ++-- src/libexpr/include/nix/expr/parser-state.hh | 25 +++++++++++++------- src/libexpr/nixexpr.cc | 6 ++--- src/nix/flake.cc | 6 ++--- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 71834f10f89..ab3f7b3ff5d 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1368,7 +1368,7 @@ void ExprVar::eval(EvalState & state, Env & env, Value & v) v = *v2; } -static std::string showAttrPath(EvalState & state, Env & env, std::span attrPath) +static std::string showAttrSelectionPath(EvalState & state, Env & env, std::span attrPath) { std::ostringstream out; bool first = true; @@ -1404,7 +1404,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) env, getPos(), "while evaluating the attribute '%1%'", - showAttrPath(state, env, getAttrPath())) + showAttrSelectionPath(state, env, getAttrPath())) : nullptr; for (auto & i : getAttrPath()) { @@ -1445,7 +1445,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) auto origin = std::get_if(&pos2r.origin); if (!(origin && *origin == state.derivationInternal)) state.addErrorTrace( - e, pos2, "while evaluating the attribute '%1%'", showAttrPath(state, env, getAttrPath())); + e, pos2, "while evaluating the attribute '%1%'", showAttrSelectionPath(state, env, getAttrPath())); } throw; } diff --git a/src/libexpr/include/nix/expr/nixexpr.hh b/src/libexpr/include/nix/expr/nixexpr.hh index c7bfb7359cb..df39ecdde91 100644 --- a/src/libexpr/include/nix/expr/nixexpr.hh +++ b/src/libexpr/include/nix/expr/nixexpr.hh @@ -87,9 +87,9 @@ struct AttrName static_assert(std::is_trivially_copy_constructible_v); -typedef std::vector AttrPath; +typedef std::vector AttrSelectionPath; -std::string showAttrPath(const SymbolTable & symbols, std::span attrPath); +std::string showAttrSelectionPath(const SymbolTable & symbols, std::span attrPath); using UpdateQueue = SmallTemporaryValueVector; diff --git a/src/libexpr/include/nix/expr/parser-state.hh b/src/libexpr/include/nix/expr/parser-state.hh index 5a94f62e82e..f9bd06589e4 100644 --- a/src/libexpr/include/nix/expr/parser-state.hh +++ b/src/libexpr/include/nix/expr/parser-state.hh @@ -163,20 +163,25 @@ struct ParserState static constexpr Expr::AstSymbols s = StaticEvalSymbols::create().exprSymbols; const EvalSettings & settings; - void dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos); + void dupAttr(const AttrSelectionPath & attrPath, const PosIdx pos, const PosIdx prevPos); void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos); void addAttr( - ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc); - void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def); + ExprAttrs * attrs, + AttrSelectionPath && attrPath, + const ParserLocation & loc, + Expr * e, + const ParserLocation & exprLoc); + void addAttr(ExprAttrs * attrs, AttrSelectionPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def); void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {}); Expr * stripIndentation(const PosIdx pos, std::span>> es); PosIdx at(const ParserLocation & loc); }; -inline void ParserState::dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos) +inline void ParserState::dupAttr(const AttrSelectionPath & attrPath, const PosIdx pos, const PosIdx prevPos) { throw ParseError( - {.msg = HintFmt("attribute '%1%' already defined at %2%", showAttrPath(symbols, attrPath), positions[prevPos]), + {.msg = HintFmt( + "attribute '%1%' already defined at %2%", showAttrSelectionPath(symbols, attrPath), positions[prevPos]), .pos = positions[pos]}); } @@ -188,9 +193,13 @@ inline void ParserState::dupAttr(Symbol attr, const PosIdx pos, const PosIdx pre } inline void ParserState::addAttr( - ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc) + ExprAttrs * attrs, + AttrSelectionPath && attrPath, + const ParserLocation & loc, + Expr * e, + const ParserLocation & exprLoc) { - AttrPath::iterator i; + AttrSelectionPath::iterator i; // All attrpaths have at least one attr assert(!attrPath.empty()); auto pos = at(loc); @@ -236,7 +245,7 @@ inline void ParserState::addAttr( * symbol as its last element. */ inline void -ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def) +ParserState::addAttr(ExprAttrs * attrs, AttrSelectionPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def) { ExprAttrs::AttrDefs::iterator j = attrs->attrs->find(symbol); if (j != attrs->attrs->end()) { diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index fc8c71b07d9..4a2f71a11b8 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -57,7 +57,7 @@ void ExprSelect::show(const SymbolTable & symbols, std::ostream & str) const { str << "("; e->show(symbols, str); - str << ")." << showAttrPath(symbols, getAttrPath()); + str << ")." << showAttrSelectionPath(symbols, getAttrPath()); if (def) { str << " or ("; def->show(symbols, str); @@ -69,7 +69,7 @@ void ExprOpHasAttr::show(const SymbolTable & symbols, std::ostream & str) const { str << "(("; e->show(symbols, str); - str << ") ? " << showAttrPath(symbols, attrPath) << ")"; + str << ") ? " << showAttrSelectionPath(symbols, attrPath) << ")"; } void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const @@ -261,7 +261,7 @@ void ExprPos::show(const SymbolTable & symbols, std::ostream & str) const str << "__curPos"; } -std::string showAttrPath(const SymbolTable & symbols, std::span attrPath) +std::string showAttrSelectionPath(const SymbolTable & symbols, std::span attrPath) { std::ostringstream out; bool first = true; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index be19b5317dd..e88a5d46c61 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -418,7 +418,7 @@ struct CmdFlakeCheck : FlakeCommand return std::nullopt; }; - std::map> attrPathsByDrv; + std::map> attrPathsByDrv; auto checkApp = [&](const std::string & attrPath, Value & v, const PosIdx pos) { try { @@ -618,7 +618,7 @@ struct CmdFlakeCheck : FlakeCommand }; // Build and store the attribute path for error reporting - AttrPath attrPath; + AttrSelectionPath attrPath; attrPath.push_back(AttrName(state->symbols.create(name))); attrPath.push_back(AttrName(attr.name)); attrPath.push_back(AttrName(attr2.name)); @@ -820,7 +820,7 @@ struct CmdFlakeCheck : FlakeCommand auto it = attrPathsByDrv.find(result.path); if (it != attrPathsByDrv.end() && !it->second.empty()) { for (auto & attrPath : it->second) { - auto attrPathStr = showAttrPath(state->symbols, attrPath); + auto attrPathStr = showAttrSelectionPath(state->symbols, attrPath); reportError(Error( "failed to build attribute '%s', build of '%s' failed: %s", attrPathStr, From 20fc54c00dd6deb31312714651bbd96d321672dd Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 5 Dec 2025 13:41:59 +0100 Subject: [PATCH 2/2] Introduce AttrPath type This is basically an alias for std::vector. --- src/libcmd/installable-flake.cc | 2 +- src/libcmd/installables.cc | 10 ++--- src/libexpr/attr-path.cc | 15 ++++++- src/libexpr/eval-cache.cc | 10 ++--- src/libexpr/include/nix/expr/attr-path.hh | 11 ++++- src/libexpr/include/nix/expr/eval-cache.hh | 7 ++-- src/libexpr/include/nix/expr/symbol-table.hh | 2 +- src/nix/flake.cc | 43 ++++++++------------ src/nix/search.cc | 19 ++++----- 9 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/libcmd/installable-flake.cc b/src/libcmd/installable-flake.cc index 65f48fa2bb7..11bbdbf8429 100644 --- a/src/libcmd/installable-flake.cc +++ b/src/libcmd/installable-flake.cc @@ -171,7 +171,7 @@ std::vector> InstallableFlake::getCursors(EvalState for (auto & attrPath : attrPaths) { debug("trying flake output attribute '%s'", attrPath); - auto attr = root->findAlongAttrPath(parseAttrPath(state, attrPath)); + auto attr = root->findAlongAttrPath(AttrPath::parse(state, attrPath)); if (attr) { res.push_back(ref(*attr)); } else { diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 2fa2280ea58..7e3861e2f1d 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -355,9 +355,9 @@ void completeFlakeRefWithFragment( attrPathPrefixes.push_back(""); for (auto & attrPathPrefixS : attrPathPrefixes) { - auto attrPathPrefix = parseAttrPath(*evalState, attrPathPrefixS); + auto attrPathPrefix = AttrPath::parse(*evalState, attrPathPrefixS); auto attrPathS = attrPathPrefixS + std::string(fragment); - auto attrPath = parseAttrPath(*evalState, attrPathS); + auto attrPath = AttrPath::parse(*evalState, attrPathS); std::string lastAttr; if (!attrPath.empty() && !hasSuffix(attrPathS, ".")) { @@ -375,9 +375,7 @@ void completeFlakeRefWithFragment( /* Strip the attrpath prefix. */ attrPath2.erase(attrPath2.begin(), attrPath2.begin() + attrPathPrefix.size()); // FIXME: handle names with dots - completions.add( - flakeRefS + "#" + prefixRoot - + concatStringsSep(".", evalState->symbols.resolve(attrPath2))); + completions.add(flakeRefS + "#" + prefixRoot + attrPath2.to_string(*evalState)); } } } @@ -386,7 +384,7 @@ void completeFlakeRefWithFragment( attrpaths. */ if (fragment.empty()) { for (auto & attrPath : defaultFlakeAttrPaths) { - auto attr = root->findAlongAttrPath(parseAttrPath(*evalState, attrPath)); + auto attr = root->findAlongAttrPath(AttrPath::parse(*evalState, attrPath)); if (!attr) continue; completions.add(flakeRefS + "#" + prefixRoot); diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc index 58705bfa1bd..575a135422a 100644 --- a/src/libexpr/attr-path.cc +++ b/src/libexpr/attr-path.cc @@ -1,5 +1,6 @@ #include "nix/expr/attr-path.hh" #include "nix/expr/eval-inline.hh" +#include "nix/util/strings-inline.hh" namespace nix { @@ -30,14 +31,24 @@ static Strings parseAttrPath(std::string_view s) return res; } -std::vector parseAttrPath(EvalState & state, std::string_view s) +AttrPath AttrPath::parse(EvalState & state, std::string_view s) { - std::vector res; + AttrPath res; for (auto & a : parseAttrPath(s)) res.push_back(state.symbols.create(a)); return res; } +std::string AttrPath::to_string(EvalState & state) const +{ + return dropEmptyInitThenConcatStringsSep(".", state.symbols.resolve({*this})); +} + +std::vector AttrPath::resolve(EvalState & state) const +{ + return state.symbols.resolve({*this}); +} + std::pair findAlongAttrPath(EvalState & state, const std::string & attrPath, Bindings & autoArgs, Value & vIn) { diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc index 4cfa3dabbac..43f10da6eac 100644 --- a/src/libexpr/eval-cache.cc +++ b/src/libexpr/eval-cache.cc @@ -364,7 +364,7 @@ void AttrCursor::fetchCachedValue() throw CachedEvalError(parent->first, parent->second); } -std::vector AttrCursor::getAttrPath() const +AttrPath AttrCursor::getAttrPath() const { if (parent) { auto attrPath = parent->first->getAttrPath(); @@ -374,7 +374,7 @@ std::vector AttrCursor::getAttrPath() const return {}; } -std::vector AttrCursor::getAttrPath(Symbol name) const +AttrPath AttrCursor::getAttrPath(Symbol name) const { auto attrPath = getAttrPath(); attrPath.push_back(name); @@ -383,12 +383,12 @@ std::vector AttrCursor::getAttrPath(Symbol name) const std::string AttrCursor::getAttrPathStr() const { - return dropEmptyInitThenConcatStringsSep(".", root->state.symbols.resolve(getAttrPath())); + return getAttrPath().to_string(root->state); } std::string AttrCursor::getAttrPathStr(Symbol name) const { - return dropEmptyInitThenConcatStringsSep(".", root->state.symbols.resolve(getAttrPath(name))); + return getAttrPath(name).to_string(root->state); } Value & AttrCursor::forceValue() @@ -511,7 +511,7 @@ ref AttrCursor::getAttr(std::string_view name) return getAttr(root->state.symbols.create(name)); } -OrSuggestions> AttrCursor::findAlongAttrPath(const std::vector & attrPath) +OrSuggestions> AttrCursor::findAlongAttrPath(const AttrPath & attrPath) { auto res = shared_from_this(); for (auto & attr : attrPath) { diff --git a/src/libexpr/include/nix/expr/attr-path.hh b/src/libexpr/include/nix/expr/attr-path.hh index 10e3e300f00..fd48705b8b7 100644 --- a/src/libexpr/include/nix/expr/attr-path.hh +++ b/src/libexpr/include/nix/expr/attr-path.hh @@ -19,6 +19,15 @@ findAlongAttrPath(EvalState & state, const std::string & attrPath, Bindings & au */ std::pair findPackageFilename(EvalState & state, Value & v, std::string what); -std::vector parseAttrPath(EvalState & state, std::string_view s); +struct AttrPath : std::vector +{ + using std::vector::vector; + + static AttrPath parse(EvalState & state, std::string_view s); + + std::string to_string(EvalState & state) const; + + std::vector resolve(EvalState & state) const; +}; } // namespace nix diff --git a/src/libexpr/include/nix/expr/eval-cache.hh b/src/libexpr/include/nix/expr/eval-cache.hh index 0a0461c192a..6d82f8c7e35 100644 --- a/src/libexpr/include/nix/expr/eval-cache.hh +++ b/src/libexpr/include/nix/expr/eval-cache.hh @@ -4,6 +4,7 @@ #include "nix/util/sync.hh" #include "nix/util/hash.hh" #include "nix/expr/eval.hh" +#include "nix/expr/attr-path.hh" #include #include @@ -124,9 +125,9 @@ public: Value * value = nullptr, std::optional> && cachedValue = {}); - std::vector getAttrPath() const; + AttrPath getAttrPath() const; - std::vector getAttrPath(Symbol name) const; + AttrPath getAttrPath(Symbol name) const; std::string getAttrPathStr() const; @@ -146,7 +147,7 @@ public: * Get an attribute along a chain of attrsets. Note that this does * not auto-call functors or functions. */ - OrSuggestions> findAlongAttrPath(const std::vector & attrPath); + OrSuggestions> findAlongAttrPath(const AttrPath & attrPath); std::string getString(); diff --git a/src/libexpr/include/nix/expr/symbol-table.hh b/src/libexpr/include/nix/expr/symbol-table.hh index ccee8bee05e..f0220376c53 100644 --- a/src/libexpr/include/nix/expr/symbol-table.hh +++ b/src/libexpr/include/nix/expr/symbol-table.hh @@ -290,7 +290,7 @@ public: return Symbol(*symbols.insert(SymbolStr::Key{store, s, buffer}).first); } - std::vector resolve(const std::vector & symbols) const + std::vector resolve(const std::span & symbols) const { std::vector result; result.reserve(symbols.size()); diff --git a/src/nix/flake.cc b/src/nix/flake.cc index e88a5d46c61..5324e0121d5 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -418,7 +418,7 @@ struct CmdFlakeCheck : FlakeCommand return std::nullopt; }; - std::map> attrPathsByDrv; + std::map> attrPathsByDrv; auto checkApp = [&](const std::string & attrPath, Value & v, const PosIdx pos) { try { @@ -618,10 +618,7 @@ struct CmdFlakeCheck : FlakeCommand }; // Build and store the attribute path for error reporting - AttrSelectionPath attrPath; - attrPath.push_back(AttrName(state->symbols.create(name))); - attrPath.push_back(AttrName(attr.name)); - attrPath.push_back(AttrName(attr2.name)); + AttrPath attrPath{state->symbols.create(name), attr.name, attr2.name}; attrPathsByDrv[path].push_back(std::move(attrPath)); } } @@ -820,10 +817,9 @@ struct CmdFlakeCheck : FlakeCommand auto it = attrPathsByDrv.find(result.path); if (it != attrPathsByDrv.end() && !it->second.empty()) { for (auto & attrPath : it->second) { - auto attrPathStr = showAttrSelectionPath(state->symbols, attrPath); reportError(Error( "failed to build attribute '%s', build of '%s' failed: %s", - attrPathStr, + attrPath.to_string(*state), result.path.to_string(*store), failure->errorMsg)); } @@ -1172,7 +1168,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON auto flake = make_ref(lockFlake()); auto localSystem = std::string(settings.thisSystem.get()); - std::function & attrPath, const Symbol & attr)> + std::function hasContent; // For frameworks it's important that structures are as lazy as possible @@ -1181,11 +1177,10 @@ struct CmdFlakeShow : FlakeCommand, MixJSON // to emit more attributes than strictly (sic) necessary. // However, these attributes with empty values are not useful to the user // so we omit them. - hasContent = - [&](eval_cache::AttrCursor & visitor, const std::vector & attrPath, const Symbol & attr) -> bool { + hasContent = [&](eval_cache::AttrCursor & visitor, const AttrPath & attrPath, const Symbol & attr) -> bool { auto attrPath2(attrPath); attrPath2.push_back(attr); - auto attrPathS = state->symbols.resolve(attrPath2); + auto attrPathS = attrPath2.resolve(*state); const auto & attrName = state->symbols[attr]; auto visitor2 = visitor.getAttr(attrName); @@ -1225,20 +1220,20 @@ struct CmdFlakeShow : FlakeCommand, MixJSON std::function & attrPath, + const AttrPath & attrPath, const std::string & headerPrefix, const std::string & nextPrefix)> visit; visit = [&](eval_cache::AttrCursor & visitor, - const std::vector & attrPath, + const AttrPath & attrPath, const std::string & headerPrefix, const std::string & nextPrefix) -> nlohmann::json { auto j = nlohmann::json::object(); - auto attrPathS = state->symbols.resolve(attrPath); + auto attrPathS = attrPath.resolve(*state); - Activity act(*logger, lvlInfo, actUnknown, fmt("evaluating '%s'", concatStringsSep(".", attrPathS))); + Activity act(*logger, lvlInfo, actUnknown, fmt("evaluating '%s'", attrPath.to_string(*state))); try { auto recurse = [&]() { @@ -1317,8 +1312,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--all-systems' to show)", headerPrefix)); else { - logger->warn( - fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS))); + logger->warn(fmt("%s omitted (use '--all-systems' to show)", attrPath.to_string(*state))); } } else { try { @@ -1335,8 +1329,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON headerPrefix)); } else { logger->warn( - fmt("%s omitted due to use of import from derivation", - concatStringsSep(".", attrPathS))); + fmt("%s omitted due to use of import from derivation", attrPath.to_string(*state))); } } } @@ -1354,8 +1347,8 @@ struct CmdFlakeShow : FlakeCommand, MixJSON fmt("%s " ANSI_WARNING "omitted due to use of import from derivation" ANSI_NORMAL, headerPrefix)); } else { - logger->warn(fmt( - "%s omitted due to use of import from derivation", concatStringsSep(".", attrPathS))); + logger->warn( + fmt("%s omitted due to use of import from derivation", attrPath.to_string(*state))); } } } @@ -1368,7 +1361,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON logger->cout(fmt( "%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--legacy' to show)", headerPrefix)); else { - logger->warn(fmt("%s omitted (use '--legacy' to show)", concatStringsSep(".", attrPathS))); + logger->warn(fmt("%s omitted (use '--legacy' to show)", attrPath.to_string(*state))); } } else if (!showAllSystems && std::string(attrPathS[1]) != localSystem) { if (!json) @@ -1376,8 +1369,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--all-systems' to show)", headerPrefix)); else { - logger->warn( - fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS))); + logger->warn(fmt("%s omitted (use '--all-systems' to show)", attrPath.to_string(*state))); } } else { try { @@ -1393,8 +1385,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON headerPrefix)); } else { logger->warn( - fmt("%s omitted due to use of import from derivation", - concatStringsSep(".", attrPathS))); + fmt("%s omitted due to use of import from derivation", attrPath.to_string(*state))); } } } diff --git a/src/nix/search.cc b/src/nix/search.cc index 20bb4cd5dff..dac60ceba57 100644 --- a/src/nix/search.cc +++ b/src/nix/search.cc @@ -90,13 +90,13 @@ struct CmdSearch : InstallableValueCommand, MixJSON uint64_t results = 0; - std::function & attrPath, bool initialRecurse)> - visit; + std::function visit; - visit = [&](eval_cache::AttrCursor & cursor, const std::vector & attrPath, bool initialRecurse) { - auto attrPathS = state->symbols.resolve(attrPath); + visit = [&](eval_cache::AttrCursor & cursor, const AttrPath & attrPath, bool initialRecurse) { + auto attrPathS = state->symbols.resolve({attrPath}); + auto attrPathStr = attrPath.to_string(*state); - Activity act(*logger, lvlInfo, actUnknown, fmt("evaluating '%s'", concatStringsSep(".", attrPathS))); + Activity act(*logger, lvlInfo, actUnknown, fmt("evaluating '%s'", attrPathStr)); try { auto recurse = [&]() { for (const auto & attr : cursor.getAttrs()) { @@ -114,7 +114,6 @@ struct CmdSearch : InstallableValueCommand, MixJSON auto aDescription = aMeta ? aMeta->maybeGetAttr(state->s.description) : nullptr; auto description = aDescription ? aDescription->getString() : ""; std::replace(description.begin(), description.end(), '\n', ' '); - auto attrPath2 = concatStringsSep(".", attrPathS); std::vector attrPathMatches; std::vector descriptionMatches; @@ -122,7 +121,7 @@ struct CmdSearch : InstallableValueCommand, MixJSON bool found = false; for (auto & regex : excludeRegexes) { - if (std::regex_search(attrPath2, regex) || std::regex_search(name.name, regex) + if (std::regex_search(attrPathStr, regex) || std::regex_search(name.name, regex) || std::regex_search(description, regex)) return; } @@ -137,7 +136,7 @@ struct CmdSearch : InstallableValueCommand, MixJSON } }; - addAll(std::sregex_iterator(attrPath2.begin(), attrPath2.end(), regex), attrPathMatches); + addAll(std::sregex_iterator(attrPathStr.begin(), attrPathStr.end(), regex), attrPathMatches); addAll(std::sregex_iterator(name.name.begin(), name.name.end(), regex), nameMatches); addAll(std::sregex_iterator(description.begin(), description.end(), regex), descriptionMatches); @@ -148,7 +147,7 @@ struct CmdSearch : InstallableValueCommand, MixJSON if (found) { results++; if (json) { - (*jsonOut)[attrPath2] = { + (*jsonOut)[attrPathStr] = { {"pname", name.name}, {"version", name.version}, {"description", description}, @@ -158,7 +157,7 @@ struct CmdSearch : InstallableValueCommand, MixJSON logger->cout(""); logger->cout( "* %s%s", - wrap("\e[0;1m", hiliteMatches(attrPath2, attrPathMatches, ANSI_GREEN, "\e[0;1m")), + wrap("\e[0;1m", hiliteMatches(attrPathStr, attrPathMatches, ANSI_GREEN, "\e[0;1m")), optionalBracket(" (", name.version, ")")); if (description != "") logger->cout(