mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-08 03:07:17 +02:00
![Théophane Hufschmitt](/assets/img/avatar_default.png)
* Factor out the default `MultiCommand` behavior All the `MultiCommand`s had (nearly) the same behavior when called without a subcommand. Factor out this behavior into the `NixMultiCommand` class. * Display the list of available subcommands when none is specified Whenever a user runs a command that excepts a subcommand, add the list of available subcommands to the error message. * Print the multi-command lists as Markdown lists This takes more screen real estate, but is also much more readable than a comma-separated list
75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
#include "command.hh"
|
|
#include "common-args.hh"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using namespace nix;
|
|
|
|
struct CmdRealisation : NixMultiCommand
|
|
{
|
|
CmdRealisation() : NixMultiCommand("realisation", RegisterCommand::getCommandsFor({"realisation"}))
|
|
{ }
|
|
|
|
std::string description() override
|
|
{
|
|
return "manipulate a Nix realisation";
|
|
}
|
|
|
|
Category category() override { return catUtility; }
|
|
};
|
|
|
|
static auto rCmdRealisation = registerCommand<CmdRealisation>("realisation");
|
|
|
|
struct CmdRealisationInfo : BuiltPathsCommand, MixJSON
|
|
{
|
|
std::string description() override
|
|
{
|
|
return "query information about one or several realisations";
|
|
}
|
|
|
|
std::string doc() override
|
|
{
|
|
return
|
|
#include "realisation/info.md"
|
|
;
|
|
}
|
|
|
|
Category category() override { return catSecondary; }
|
|
|
|
void run(ref<Store> store, BuiltPaths && paths) override
|
|
{
|
|
experimentalFeatureSettings.require(Xp::CaDerivations);
|
|
RealisedPath::Set realisations;
|
|
|
|
for (auto & builtPath : paths) {
|
|
auto theseRealisations = builtPath.toRealisedPaths(*store);
|
|
realisations.insert(theseRealisations.begin(), theseRealisations.end());
|
|
}
|
|
|
|
if (json) {
|
|
nlohmann::json res = nlohmann::json::array();
|
|
for (auto & path : realisations) {
|
|
nlohmann::json currentPath;
|
|
if (auto realisation = std::get_if<Realisation>(&path.raw))
|
|
currentPath = realisation->toJSON();
|
|
else
|
|
currentPath["opaquePath"] = store->printStorePath(path.path());
|
|
|
|
res.push_back(currentPath);
|
|
}
|
|
logger->cout("%s", res);
|
|
}
|
|
else {
|
|
for (auto & path : realisations) {
|
|
if (auto realisation = std::get_if<Realisation>(&path.raw)) {
|
|
logger->cout("%s %s",
|
|
realisation->id.to_string(),
|
|
store->printStorePath(realisation->outPath));
|
|
} else
|
|
logger->cout("%s", store->printStorePath(path.path()));
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
static auto rCmdRealisationInfo = registerCommand2<CmdRealisationInfo>({"realisation", "info"});
|