forked from lix-project/lix
Merge branch 'improve-search-algorithm' of git://github.com/Ma27/nix
This commit is contained in:
commit
3748a0ca1e
|
@ -82,8 +82,6 @@ struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
|
|
||||||
auto state = getEvalState();
|
auto state = getEvalState();
|
||||||
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
auto jsonOut = json ? std::make_unique<JSONObject>(std::cout) : nullptr;
|
auto jsonOut = json ? std::make_unique<JSONObject>(std::cout) : nullptr;
|
||||||
|
|
||||||
auto sToplevel = state->symbols.create("_toplevel");
|
auto sToplevel = state->symbols.create("_toplevel");
|
||||||
|
@ -91,6 +89,8 @@ struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
|
|
||||||
bool fromCache = false;
|
bool fromCache = false;
|
||||||
|
|
||||||
|
std::map<std::string, std::string> results;
|
||||||
|
|
||||||
std::function<void(Value *, std::string, bool, JSONObject *)> doExpr;
|
std::function<void(Value *, std::string, bool, JSONObject *)> doExpr;
|
||||||
|
|
||||||
doExpr = [&](Value * v, std::string attrPath, bool toplevel, JSONObject * cache) {
|
doExpr = [&](Value * v, std::string attrPath, bool toplevel, JSONObject * cache) {
|
||||||
|
@ -138,10 +138,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
jsonElem.attr("description", description);
|
jsonElem.attr("description", description);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!first) std::cout << "\n";
|
results[attrPath] = fmt(
|
||||||
first = false;
|
|
||||||
|
|
||||||
std::cout << fmt(
|
|
||||||
"Attribute name: %s\n"
|
"Attribute name: %s\n"
|
||||||
"Package name: %s\n"
|
"Package name: %s\n"
|
||||||
"Version: %s\n"
|
"Version: %s\n"
|
||||||
|
@ -240,6 +237,9 @@ struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
if (rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
|
if (rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1)
|
||||||
throw SysError("cannot rename '%s' to '%s'", tmpFile, jsonCacheFileName);
|
throw SysError("cannot rename '%s' to '%s'", tmpFile, jsonCacheFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto el : results) std::cout << el.second << "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue