printFlakeInfo: Separate JSON output

This commit is contained in:
Eelco Dolstra 2019-05-28 14:01:57 +02:00
parent ecee759b80
commit 46294d60cd
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -94,34 +94,36 @@ static void sourceInfoToJson(const SourceInfo & sourceInfo, nlohmann::json & j)
j["path"] = sourceInfo.storePath;
}
static void printFlakeInfo(const Flake & flake, bool json)
static void printFlakeInfo(const Flake & flake)
{
if (json) {
nlohmann::json j;
j["id"] = flake.id;
j["description"] = flake.description;
j["epoch"] = flake.epoch;
sourceInfoToJson(flake.sourceInfo, j);
std::cout << j.dump(4) << std::endl;
} else {
std::cout << "ID: " << flake.id << "\n";
std::cout << "Description: " << flake.description << "\n";
std::cout << "Epoch: " << flake.epoch << "\n";
printSourceInfo(flake.sourceInfo);
}
static nlohmann::json flakeToJson(const Flake & flake)
{
nlohmann::json j;
j["id"] = flake.id;
j["description"] = flake.description;
j["epoch"] = flake.epoch;
sourceInfoToJson(flake.sourceInfo, j);
return j;
}
static void printNonFlakeInfo(const NonFlake & nonFlake, bool json)
static void printNonFlakeInfo(const NonFlake & nonFlake)
{
if (json) {
nlohmann::json j;
j["id"] = nonFlake.alias;
printSourceInfo(nonFlake.sourceInfo);
std::cout << j.dump(4) << std::endl;
} else {
std::cout << "ID: " << nonFlake.alias << "\n";
printSourceInfo(nonFlake.sourceInfo);
}
static nlohmann::json nonFlakeToJson(const NonFlake & nonFlake)
{
nlohmann::json j;
j["id"] = nonFlake.alias;
sourceInfoToJson(nonFlake.sourceInfo, j);
return j;
}
// FIXME: merge info CmdFlakeInfo?
@ -152,10 +154,10 @@ struct CmdFlakeDeps : FlakeCommand
todo.pop();
for (auto & nonFlake : resFlake.nonFlakeDeps)
printNonFlakeInfo(nonFlake, false);
printNonFlakeInfo(nonFlake);
for (auto & info : resFlake.flakeDeps) {
printFlakeInfo(info.second.flake, false);
printFlakeInfo(info.second.flake);
todo.push(info.second);
}
}
@ -205,7 +207,10 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON
{
auto flake = getFlake();
stopProgressBar();
printFlakeInfo(flake, json);
if (json)
std::cout << flakeToJson(flake).dump() << std::endl;
else
printFlakeInfo(flake);
}
};