args  6.2.0
A simple single-header C++11 STL-only argument parser library
Public Member Functions | List of all members
args::Subparser Class Reference

Utility class for building subparsers with coroutines/callbacks. More...

#include <args.hxx>

Inheritance diagram for args::Subparser:
args::Group args::Base

Public Member Functions

 Subparser (std::vector< std::string > args_, ArgumentParser &parser_, const Command &command_, const HelpParams &helpParams_)
 
 Subparser (const Command &command_, const HelpParams &helpParams_)
 
 Subparser (const Subparser &)=delete
 
 Subparser (Subparser &&)=delete
 
Subparseroperator= (const Subparser &)=delete
 
Subparseroperator= (Subparser &&)=delete
 
const CommandGetCommand ()
 
bool IsParsed () const
 (INTERNAL) Determines whether Parse was called or not.
 
void Parse ()
 Continue parsing arguments for new command.
 
const std::vector< std::string > & KickedOut () const noexcept
 Returns a vector of kicked out arguments. More...
 
- Public Member Functions inherited from args::Group
 Group (const std::string &help_=std::string(), const std::function< bool(const Group &)> &validator_=Validators::DontCare, Options options_={})
 If help is empty, this group will not be printed in help output.
 
 Group (Group &group_, const std::string &help_=std::string(), const std::function< bool(const Group &)> &validator_=Validators::DontCare, Options options_={})
 If help is empty, this group will not be printed in help output.
 
void Add (Base &child)
 Append a child to this Group.
 
const std::vector< Base * > & Children () const
 Get all this group's children.
 
virtual FlagBaseMatch (const EitherFlag &flag) override
 Return the first FlagBase that matches flag, or nullptr. More...
 
virtual std::vector< FlagBase * > GetAllFlags () override
 
virtual void Validate (const std::string &shortPrefix, const std::string &longPrefix) const override
 
virtual PositionalBaseGetNextPositional () override
 Get the next ready positional, or nullptr if there is none. More...
 
virtual bool HasFlag () const override
 Get whether this has any FlagBase children. More...
 
virtual bool HasPositional () const override
 Get whether this has any PositionalBase children. More...
 
virtual bool HasCommand () const override
 Get whether this has any Command children. More...
 
std::vector< Base * >::size_type MatchedChildren () const
 Count the number of matched children this group has.
 
virtual bool Matched () const noexcept override
 Whether or not this group matches validation.
 
bool Get () const
 Get validation.
 
virtual std::vector< std::tuple< std::string, std::string, unsigned > > GetDescription (const HelpParams &params, const unsigned int indent) const override
 Get all the child descriptions for help generation.
 
virtual std::vector< std::string > GetProgramLine (const HelpParams &params) const override
 Get the names of positional parameters.
 
virtual std::vector< Command * > GetCommands () override
 
virtual bool IsGroup () const override
 
virtual void Reset () noexcept override
 
- Public Member Functions inherited from args::Base
 Base (const std::string &help_, Options options_={})
 
Options GetOptions () const noexcept
 
bool IsRequired () const noexcept
 
 operator bool () const noexcept
 
virtual std::vector< std::tuple< std::string, std::string, unsigned > > GetDescription (const HelpParams &, const unsigned indentLevel) const
 
void KickOut (bool kickout_) noexcept
 Sets a kick-out value for building subparsers.
 
bool KickOut () const noexcept
 Gets the kick-out value for building subparsers.
 

Additional Inherited Members

- Protected Attributes inherited from args::Base
bool matched = false
 
const std::string help
 

Detailed Description

Utility class for building subparsers with coroutines/callbacks.

Brief example:

Command command(argumentParser, "command", "my command", [](args::Subparser &s)
{
// your command flags/positionals
s.Parse(); //required
//your command code
});
Utility class for building subparsers with coroutines/callbacks.
Definition: args.hxx:1657
void Parse()
Continue parsing arguments for new command.
Definition: args.hxx:3117

For ARGS_NOEXCEPT mode don't forget to check s.GetError() after s.Parse() and return if it isn't equals to args::Error::None.

See also
Command

Member Function Documentation

◆ KickedOut()

const std::vector<std::string>& args::Subparser::KickedOut ( ) const
inlinenoexcept

Returns a vector of kicked out arguments.

See also
Base::KickOut

The documentation for this class was generated from the following file: