Skip to content

Commit

Permalink
search.cc: sort attribute names with std::map
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma27 committed Dec 12, 2017
1 parent 1ca8e95 commit 0413aeb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/nix/search.cc
Expand Up @@ -82,15 +82,15 @@ struct CmdSearch : SourceExprCommand, MixJSON

auto state = getEvalState();

bool first = true;

auto jsonOut = json ? std::make_unique<JSONObject>(std::cout) : nullptr;

auto sToplevel = state->symbols.create("_toplevel");
auto sRecurse = state->symbols.create("recurseForDerivations");

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) {
Expand Down Expand Up @@ -138,10 +138,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"
Expand Down Expand Up @@ -240,6 +237,9 @@ struct CmdSearch : SourceExprCommand, MixJSON
if (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";

}
};

Expand Down

0 comments on commit 0413aeb

Please sign in to comment.