Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::MixPrintJSON Struct Reference

#include <common-args.hh>

Inheritance diagram for nix::MixPrintJSON:
nix::Args nix::CmdShowDerivation nix::MixJSON nix::CmdBuild nix::CmdBuildTraceInfo nix::CmdConfigShow nix::CmdEval nix::CmdFlakeArchive nix::CmdFlakeMetadata nix::CmdFlakePrefetch nix::CmdFlakeShow nix::CmdFormatterRun nix::CmdInfoStore nix::CmdMakeContentAddressed nix::CmdPathInfo nix::CmdPrintDevEnv nix::CmdProfileList nix::CmdSearch nix::CmdStorePrefetchFile nix::CmdVersion nix::MixLs

Public Member Functions

template<typename T, typename = std::enable_if_t<std::is_same_v<T, nlohmann::json>>>
void printJSON (const T &json)
Public Member Functions inherited from nix::Args
virtual std::string description ()
virtual bool forceImpureByDefault ()
virtual std::string doc ()
virtual std::filesystem::path getCommandBaseDir () const
 Get the base directory for the command.
void addFlag (Flag &&flag)
void removeFlag (const std::string &longName)
void expectArgs (ExpectedArg &&arg)
void expectArg (const std::string &label, std::string *dest, bool optional=false)
void expectArg (const std::string &label, std::filesystem::path *dest, bool optional=false)
void expectArgs (const std::string &label, std::vector< std::string > *dest)
virtual nlohmann::json toJSON ()
RootArgs & getRoot ()

Public Attributes

bool outputPretty = isTTY(getStandardOutput())
Public Attributes inherited from nix::Args
MultiCommand * parent = nullptr

Additional Inherited Members

Static Public Attributes inherited from nix::Args
static CompleterFun completePath
static CompleterFun completeDir
Protected Types inherited from nix::Args
using CompleterFun = void(AddCompletions &, size_t, std::string_view)
using CompleterClosure = std::function<CompleterFun>
Protected Member Functions inherited from nix::Args
virtual bool processFlag (Strings::iterator &pos, Strings::iterator end)
virtual bool processArgs (const Strings &args, bool finish)
virtual Strings::iterator rewriteArgs (Strings &args, Strings::iterator pos)
virtual void checkArgs ()
virtual void initialFlagsProcessed ()
Protected Attributes inherited from nix::Args
std::map< std::string, Flag::ptr > longFlags
std::map< char, Flag::ptr > shortFlags
std::list< ExpectedArg > expectedArgs
std::list< ExpectedArg > processedArgs
StringSet hiddenCategories
Static Protected Attributes inherited from nix::Args
static const size_t ArityAny = std::numeric_limits<size_t>::max()

Detailed Description

Commands that can print JSON according to the --pretty/--no-pretty flag.

This is distinct from MixJSON, because for some commands, JSON outputs is not optional.

Member Function Documentation

◆ printJSON()

template<typename T, typename>
template void nix::MixPrintJSON::printJSON ( const T & json)

Print an nlohmann::json to stdout

  • respecting --pretty / --no-pretty.
  • suspending the progress bar

This is a template to avoid accidental coercions from string to json in the caller, to avoid mistakenly passing an already serialized JSON to this function.

It is not recommended to print a JSON string - see the data modeling guidelines about extensibility, https://nix.dev/manual/nix/development/development/data-modeling.html - but you can print a sole JSON string by explicitly coercing it to nlohmann::json first.


The documentation for this struct was generated from the following files: