Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::Args Class Referenceabstract
Inheritance diagram for nix::Args:
nix::CmdFlakeInitCommon nix::Command nix::FlakeCommand nix::InstallableCommand nix::MixCat nix::MixCommonArgs nix::MixDryRun nix::MixEnvironment nix::MixEvalArgs nix::MixFlakeOptions nix::MixJSON nix::MixLs nix::MixOperateOnOptions nix::MixProfileElementMatchers nix::MixReadOnlyOption nix::MixRepair nix::RawInstallablesCommand nix::RegistryCommand nix::SourceExprCommand

Classes

struct  Handler
struct  Flag
struct  ExpectedArg

Public Member Functions

virtual std::string description ()
virtual bool forceImpureByDefault ()
virtual std::string doc ()
virtual AsyncIoRootaio ()=0
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 expectArgs (const std::string &label, std::vector< std::string > *dest)
virtual JSON toJSON ()
RootArgs & getRoot ()

Public Attributes

MultiCommand * parent = nullptr

Static Public Attributes

static CompleterFun completePath
static CompleterFun completeDir

Protected Types

typedef void CompleterFun(AddCompletions &, size_t, std::string_view)
typedef std::function< CompleterFunCompleterClosure

Protected Member Functions

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 initialFlagsProcessed ()
virtual std::optional< std::reference_wrapper< RootArgs > > asRootArgs ()

Protected Attributes

std::map< std::string, Flag::ptr > longFlags
std::map< char, Flag::ptr > shortFlags
std::list< ExpectedArgexpectedArgs
std::list< ExpectedArgprocessedArgs
std::set< std::string > hiddenCategories

Static Protected Attributes

static const size_t ArityAny = std::numeric_limits<size_t>::max()

Friends

class MultiCommand

Member Typedef Documentation

◆ CompleterClosure

typedef std::function<CompleterFun> nix::Args::CompleterClosure
protected

The closure type of the completion callback.

This is what is actually stored as part of each Flag / Expected Arg.

◆ CompleterFun

typedef void nix::Args::CompleterFun(AddCompletions &, size_t, std::string_view)
protected

The basic function type of the completion callback.

Used to define CompleterClosure and some common case completers that individual flags/arguments can use.

The AddCompletions that is passed is an interface to the state stored as part of the root command

Member Function Documentation

◆ asRootArgs()

virtual std::optional< std::reference_wrapper< RootArgs > > nix::Args::asRootArgs ( )
inlineprotectedvirtual

Returns this Args as a RootArgs if it is one, or std::nullopt otherwise.

◆ description()

virtual std::string nix::Args::description ( )
inlinevirtual

Return a short one-line description of the command.

Reimplemented in nix::CmdAddDerivation, nix::CmdAddFile, nix::CmdAddPath, nix::CmdBuild, nix::CmdBundle, nix::CmdCatNar, nix::CmdCatStore, nix::CmdConfig, nix::CmdConfigShow, nix::CmdCopy, nix::CmdCopyLog, nix::CmdCopySigs, nix::CmdDaemon, nix::CmdDerivation, nix::CmdDevelop, nix::CmdDiffClosures, nix::CmdDoctor, nix::CmdDumpPath2, nix::CmdDumpPath, nix::CmdEdit, nix::CmdEval, nix::CmdFlake, nix::CmdFlakeArchive, nix::CmdFlakeCheck, nix::CmdFlakeClone, nix::CmdFlakeInit, nix::CmdFlakeLock, nix::CmdFlakeMetadata, nix::CmdFlakeNew, nix::CmdFlakePrefetch, nix::CmdFlakeShow, nix::CmdFlakeUpdate, nix::CmdFmt, nix::CmdHash, nix::CmdHashBase, nix::CmdHelp, nix::CmdHelpStores, nix::CmdKey, nix::CmdKeyConvertSecretToPublic, nix::CmdKeyGenerateSecret, nix::CmdLog, nix::CmdLsNar, nix::CmdLsStore, nix::CmdMakeContentAddressed, nix::CmdNar, nix::CmdOptimiseStore, nix::CmdPathFromHashPart, nix::CmdPathInfo, nix::CmdPingStore, nix::CmdPrintDevEnv, nix::CmdProfile, nix::CmdProfileDiffClosures, nix::CmdProfileHistory, nix::CmdProfileInstall, nix::CmdProfileList, nix::CmdProfileRemove, nix::CmdProfileRollback, nix::CmdProfileUpgrade, nix::CmdProfileWipeHistory, nix::CmdRealisation, nix::CmdRealisationInfo, nix::CmdRegistry, nix::CmdRegistryAdd, nix::CmdRegistryList, nix::CmdRegistryPin, nix::CmdRegistryRemove, nix::CmdRepl, nix::CmdRun, nix::CmdSearch, nix::CmdShell, nix::CmdShowDerivation, nix::CmdSign, nix::CmdStore, nix::CmdStoreDelete, nix::CmdStoreGC, nix::CmdStorePrefetchFile, nix::CmdStoreRepair, nix::CmdToBase, nix::CmdUpgradeNix, nix::CmdVerify, nix::CmdWhyDepends, and nix::NixArgs.

◆ doc()

virtual std::string nix::Args::doc ( )
inlinevirtual

◆ expectArg()

void nix::Args::expectArg ( const std::string & label,
std::string * dest,
bool optional = false )
inline

Expect a string argument.

◆ expectArgs()

void nix::Args::expectArgs ( const std::string & label,
std::vector< std::string > * dest )
inline

Expect 0 or more arguments.

◆ getRoot()

RootArgs & nix::Args::getRoot ( )

Traverse parent pointers until we find the rootarguments object.

◆ initialFlagsProcessed()

virtual void nix::Args::initialFlagsProcessed ( )
inlineprotectedvirtual

Called after all command line flags before the first non-flag argument (if any) have been processed.

◆ processArgs()

bool nix::Args::processArgs ( const Strings & args,
bool finish )
protectedvirtual

Process some positional arugments

Parameters
finishWe have parsed everything else, and these are the only arguments left. Used because we accumulate some "pending args" we might have left over.
Returns
true if the passed arguments were fully consumed and no further processing is required, false if the passed arguments should be processed with more context.

Reimplemented in nix::ExternalCommand, nix::LegacyArgs, and nix::MultiCommand.

◆ processFlag()

bool nix::Args::processFlag ( Strings::iterator & pos,
Strings::iterator end )
protectedvirtual

Process a single flag and its arguments, pulling from an iterator of raw CLI args as needed.

Returns
false if the flag is not recognised.

Reimplemented in nix::ExternalCommand, nix::LegacyArgs, and nix::MultiCommand.

Member Data Documentation

◆ ArityAny

const size_t nix::Args::ArityAny = std::numeric_limits<size_t>::max()
staticprotected

The largest size_t is used to indicate the "any" arity, for handlers/flags/arguments that accept an arbitrary number of arguments.

◆ expectedArgs

std::list<ExpectedArg> nix::Args::expectedArgs
protected

Queue of expected positional argument forms.

Positional argument descriptions are inserted on the back.

As positional arguments are passed, these are popped from the front, until there are hopefully none left as all args that were expected in fact were passed.

◆ longFlags

std::map<std::string, Flag::ptr> nix::Args::longFlags
protected

Index of all registered "long" flag descriptions (flags like --long).

◆ parent

MultiCommand* nix::Args::parent = nullptr

The parent command, used if this is a subcommand.

Invariant: An Args with a null parent must also be a RootArgs

Todo
this would probably be better in the CommandClass. getRoot() could be an abstract method that peels off at most one layer before recuring.

◆ processedArgs

std::list<ExpectedArg> nix::Args::processedArgs
protected

List of processed positional argument forms.

All items removed from expectedArgs are added here. After all arguments were processed, this list should be exactly the same as expectedArgs was before.

This list is used to extend the lifetime of the argument forms. If this is not done, some closures that reference the command itself will segfault.

◆ shortFlags

std::map<char, Flag::ptr> nix::Args::shortFlags
protected

Index of all registered "short" flag descriptions (flags like -s).


The documentation for this class was generated from the following files:
  • lix/libutil/args.hh
  • lix/libutil/args.cc