diff options
Diffstat (limited to 'src/nix/search.cc')
-rw-r--r-- | src/nix/search.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/nix/search.cc b/src/nix/search.cc index 87cdb2d7e..5ccf1b7cf 100644 --- a/src/nix/search.cc +++ b/src/nix/search.cc @@ -78,12 +78,15 @@ struct CmdSearch : SourceExprCommand, MixJSON { settings.readOnlyMode = true; + // Empty search string should match all packages + // Use "^" here instead of ".*" due to differences in resulting highlighting + // (see #1893 -- libc++ claims empty search string is not in POSIX grammar) + if (re.empty()) re = "^"; + std::regex regex(re, std::regex::extended | std::regex::icase); auto state = getEvalState(); - bool first = true; - auto jsonOut = json ? std::make_unique<JSONObject>(std::cout) : nullptr; auto sToplevel = state->symbols.create("_toplevel"); @@ -91,6 +94,8 @@ struct CmdSearch : SourceExprCommand, MixJSON bool fromCache = false; + std::map<std::string, std::string> results; + std::function<void(Value *, std::string, bool, JSONObject *)> doExpr; doExpr = [&](Value * v, std::string attrPath, bool toplevel, JSONObject * cache) { @@ -138,10 +143,7 @@ struct CmdSearch : SourceExprCommand, MixJSON jsonElem.attr("description", description); } else { - if (!first) std::cout << "\n"; - first = false; - - std::cout << fmt( + results[attrPath] = fmt( "Attribute name: %s\n" "Package name: %s\n" "Version: %s\n" @@ -237,9 +239,12 @@ struct CmdSearch : SourceExprCommand, MixJSON throw Error("error writing to %s", tmpFile); } - if (rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1) + if (writeCache && rename(tmpFile.c_str(), jsonCacheFileName.c_str()) == -1) throw SysError("cannot rename '%s' to '%s'", tmpFile, jsonCacheFileName); } + + for (auto el : results) std::cout << el.second << "\n"; + } }; |