koutil
Loading...
Searching...
No Matches
koutil::argparser Namespace Reference

Classes

struct  Arg
 Base structure representing a subcommand argument. More...
 
class  Arguments
 Base class for argument collections. More...
 
class  ArgumentsBase
 
class  Commands
 Collection of subcommands. More...
 
class  Commands< Cmd >
 Specialization of Commands for a single subcommand. More...
 
class  CommandsBase
 Base class for commands. More...
 
class  Parser
 Template class representing a parser. More...
 
struct  Subcommand
 Subcommand template struct. More...
 
struct  Subcommand< type::types< Args... >, type::types< Cmd... > >
 Specialization of Subcommand for argument and subcommand types. More...
 
struct  SubcommandBase
 Base class for subcommands. More...
 

Concepts

concept  is_arg
 Checks if a type is Arg.
 
concept  are_arguments
 Checks if a type is derived from ArgumentsBase.
 
concept  parser
 Concept to check if a type is a parser.
 
concept  is_subcommand
 Concept to check if a type satisfies the requirements of a subcommand.
 
concept  are_commands
 Concept to check if a type satisfies the requirements of a collection of commands.
 

Enumerations

enum class  ParseResult {
  OK , ERR , ERR_EMPTY_OPTION , ERR_UNKNOWN ,
  ERR_INVALID_VALUE , ERR_MISSING_VALUE
}
 Enum class representing possible parse results. More...
 

Functions

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
constexpr auto make_parser (Ctx &ctx, Args &&args, Cmds &&commands)
 Creates a Parser object.
 
template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ParseResult process_args (std::size_t argc, const char **argv, Ctx &ctx, Args &&args, Cmds &&commands)
 Processes the command-line arguments.
 
template<is_arg... Args, is_subcommand... Cmds>
constexpr auto make_subcommand (std::string_view name, const Arguments< Args... > &args=Arguments<> {}, const Commands< Cmds... > &cmds=Commands<> {})
 Helper function to create a subcommand.
 

Enumeration Type Documentation

◆ ParseResult

enum class koutil::argparser::ParseResult
strong

Enum class representing possible parse results.

Enumerator
OK 

Parsing succeeded.

ERR 

General error during parsing.

ERR_EMPTY_OPTION 

Error due to empty option.

ERR_UNKNOWN 

Error due to unknown option or command.

ERR_INVALID_VALUE 

Error due to invalid value for an option.

ERR_MISSING_VALUE 

Error due to missing value for an option.

Function Documentation

◆ make_parser()

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
auto koutil::argparser::make_parser ( Ctx & ctx,
Args && args,
Cmds && commands )
constexpr

Creates a Parser object.

Template Parameters
CtxThe context type.
UParserThe user-defined parser type.
ArgsThe argument types.
CmdsThe command types.
Parameters
ctxThe context.
argsThe arguments.
commandsThe commands.
Returns
A Parser object.

◆ make_subcommand()

template<is_arg... Args, is_subcommand... Cmds>
auto koutil::argparser::make_subcommand ( std::string_view name,
const Arguments< Args... > & args = Arguments<> {},
const Commands< Cmds... > & cmds = Commands<> {} )
constexpr

Helper function to create a subcommand.

Template Parameters
ArgsArgument types.
CmdsSubcommand types.
Parameters
nameThe name of the subcommand.
argsThe arguments of the subcommand.
cmdsThe subcommands of the subcommand.
Returns
A Subcommand object.

◆ process_args()

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ParseResult koutil::argparser::process_args ( std::size_t argc,
const char ** argv,
Ctx & ctx,
Args && args,
Cmds && commands )

Processes the command-line arguments.

Template Parameters
CtxThe context type.
UParserThe user-defined parser type.
ArgsThe argument types.
CmdsThe command types.
Parameters
argcThe argument count.
argvThe argument values.
ctxThe context.
argsThe arguments.
commandsThe commands.
Returns
The result of the parsing.