1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 23:42:43 +01:00

nix-cli: Add --json --pretty / --no-pretty

Default: istty(stdout)

This refactors `nix develop` internals a bit to use the `json` type
more. The assertion now operates in the in-memory json instead of
re-parsing it. While this is technically a weaker guarantee, we
should be able to rely on the library to get this right. It's its
most essential purpose.
This commit is contained in:
Robert Hensing 2025-03-13 20:19:21 +00:00
parent e9af7a0749
commit fe00dfbd56
17 changed files with 151 additions and 29 deletions

View file

@ -1,3 +1,5 @@
#include <nlohmann/json.hpp>
#include "common-args.hh"
#include "args/root.hh"
#include "config-global.hh"
@ -93,5 +95,18 @@ void MixCommonArgs::initialFlagsProcessed()
pluginsInited();
}
template <typename T, typename>
void MixPrintJSON::printJSON(const T /* nlohmann::json */ & json)
{
auto suspension = logger->suspend();
if (outputPretty) {
logger->writeToStdout(json.dump(2));
} else {
logger->writeToStdout(json.dump());
}
}
template void MixPrintJSON::printJSON(const nlohmann::json & json);
} // namespace nix