Implemented json flag for nix flake info
This commit is contained in:
parent
cfb6ab80ce
commit
9ff1a9ea65
|
@ -141,7 +141,7 @@ static FlakeSourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef)
|
|||
else abort();
|
||||
}
|
||||
|
||||
static Flake getFlake(EvalState & state, const FlakeRef & flakeRef)
|
||||
Flake getFlake(EvalState & state, const FlakeRef & flakeRef)
|
||||
{
|
||||
auto sourceInfo = fetchFlake(state, flakeRef);
|
||||
debug("got flake source '%s' with revision %s",
|
||||
|
|
|
@ -34,5 +34,5 @@ struct Flake
|
|||
// content hash
|
||||
};
|
||||
|
||||
static Flake getFlake(EvalState & state, const FlakeRef & flakeRef);
|
||||
Flake getFlake(EvalState & state, const FlakeRef & flakeRef);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,15 @@ void StoreCommand::run()
|
|||
run(getStore());
|
||||
}
|
||||
|
||||
JsonFormattable::JsonFormattable()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("json-formattable")
|
||||
.shortName('j')
|
||||
.description("output will be printed as json")
|
||||
.handler([&]() { jsonFormatting = true; });
|
||||
}
|
||||
|
||||
StorePathsCommand::StorePathsCommand(bool recursive)
|
||||
: recursive(recursive)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,13 @@ private:
|
|||
std::shared_ptr<Store> _store;
|
||||
};
|
||||
|
||||
struct JsonFormattable : virtual Command
|
||||
{
|
||||
bool jsonFormatting = false;;
|
||||
|
||||
JsonFormattable();
|
||||
};
|
||||
|
||||
struct Buildable
|
||||
{
|
||||
Path drvPath; // may be empty
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "shared.hh"
|
||||
#include "progress-bar.hh"
|
||||
#include "eval.hh"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace nix;
|
||||
|
||||
|
@ -33,7 +34,7 @@ struct CmdFlakeList : StoreCommand, MixEvalArgs
|
|||
}
|
||||
};
|
||||
|
||||
struct CmdFlakeInfo : FlakeCommand
|
||||
struct CmdFlakeInfo : FlakeCommand, JsonFormattable
|
||||
{
|
||||
std::string name() override
|
||||
{
|
||||
|
@ -49,9 +50,16 @@ struct CmdFlakeInfo : FlakeCommand
|
|||
{
|
||||
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
||||
nix::Flake flake = nix::getFlake(*evalState, FlakeRef(flakeUri));
|
||||
if (jsonFormatting) {
|
||||
nlohmann::json j;
|
||||
j["location"] = flake.path;
|
||||
j["description"] = flake.description;
|
||||
std::cout << j.dump(4) << std::endl;
|
||||
} else {
|
||||
std::cout << "Location: " << flake.path << "\n";
|
||||
std::cout << "Description: " << flake.description << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdFlake : virtual MultiCommand, virtual Command
|
||||
|
|
Loading…
Reference in a new issue