cmdline.ext

The extenstion module for Cmdline

This module give a new programming way to build the command line prgram. And it is publicly imported into main modlue cmdline.

Using the following mixin-macro which are used for being embedded in a struct whose name is end with Result and fields must be among ArgVal, OptVal and the pointer to other structs that are satisfied with and the two function coustruct and parse, you can build and parse the command line argument and option parameters. And Also, We can get the parsed value from command line more easily.

Members

Enums

__CMDLINE_EXT_isInnerArgValField__
eponymoustemplate __CMDLINE_EXT_isInnerArgValField__(T)
Undocumented in source.
__CMDLINE_EXT_isInnerOptValField__
eponymoustemplate __CMDLINE_EXT_isInnerOptValField__(T)
Undocumented in source.
__CMDLINE_EXT_isInnerSubField__
eponymoustemplate __CMDLINE_EXT_isInnerSubField__(T)
Undocumented in source.
__CMDLINE_EXT_isInnerValFieldOrResult__
eponymoustemplate __CMDLINE_EXT_isInnerValFieldOrResult__(T)
Undocumented in source.
__CMDLINE_EXT_isInnerValField__
eponymoustemplate __CMDLINE_EXT_isInnerValField__(T)
Undocumented in source.
__CMDLINE_isFieldDef__
eponymoustemplate __CMDLINE_isFieldDef__(T)
Undocumented in source.
isOutputResult
eponymoustemplate isOutputResult(T)

check whether a type is the struct that can be the container to store the parsed value from command line.

Functions

construct
Command construct()

construct the command line program without action callback

getParent
T* getParent(U subOutput)

get the pointer to result container of parent.

getParent
T* getParent(const(U)* subOutput)

get the pointer to result container of parent.

parse
T* parse(string[] argv)

parse the command line option and argument parameters according to the given command conatiner type. T = the command conatiner type

ready
bool ready(U* output)

detect whether a sub command's container of a main command is ready for use. for using this function, the BEGIN and END mixin-macro must be embeed in main command container. T is the type in sub-command container, U is the type in main-command container

run
void run(string[] argv)

parse the command line option and argument parameters according to the given command conatiner type. And invoke the action member function and return if exists, otherwise invoke member container's action member function recursely. T = the root command container type

subResult
inout(T)* subResult(inout(U)* output)

get a pointer to sub-command container. T is the type in sub-command container, U is the type in main-command container

Mixin templates

ALIAS
mixintemplate ALIAS(string name)

set an alias

BEGIN
mixintemplate BEGIN()

prepare for the future use of function ready and getParent, which must be embedded at the top of struct domain with END mixin-marco at the end of this struct domain.

CHOICES
mixintemplate CHOICES(alias field, Args...)

set the choices list to a registered option or argument

CONFIG
mixintemplate CONFIG(string flags = "")

enable gaining value from config file in json and set an option that specifies the directories where the config file should be

DEF
mixintemplate DEF(string name, T, Args...)

the basic version of both DEF_ARG and DEF_OPT

DEFAULT
mixintemplate DEFAULT(alias field, alias val)

set the default value to a registered option or argument

DEFAULT
mixintemplate DEFAULT(alias sub)

set the default sub-command which would act like the main-command except help, version and config options and sub-command if exists.

DEF_ARG
mixintemplate DEF_ARG(string name, T, Args...)

use for defining a command line argument

DEF_OPT
mixintemplate DEF_OPT(string name, T, string flag, Args...)

use for defining a command line option

DESC
mixintemplate DESC(alias field, string desc)

Add description to a registered option or argument.

DESC
mixintemplate DESC(string desc)

set description

DESC_ARG
mixintemplate DESC_ARG(alias field, string desc)

Add description to a registered argument.

DESC_OPT
mixintemplate DESC_OPT(alias field, string desc)

Add description to a registered option.

DISABLE_HELP
mixintemplate DISABLE_HELP()

disable the help sub-command and action-option

DISABLE_MERGE
mixintemplate DISABLE_MERGE(alias field)

disable the merge feature of a registered variadic option

DISABLE_MERGE
mixintemplate DISABLE_MERGE()

<br><br> disable the feature that variadic options under the command can merge value from various source

DISALLOW_COMBINE
mixintemplate DISALLOW_COMBINE()

disallow the feature that can combine flags

DISALLOW_EXCESS_ARGS
mixintemplate DISALLOW_EXCESS_ARGS()

disallow the excess arguments

END
mixintemplate END()

prepare for the future use of function ready and getParent, which must be embedded at the end of struct domain with BEGIN mixin-marco at the begin of this struct domain.

ENV
mixintemplate ENV(alias field, string envKey)

set the env key from which get the values to a registered option

EXPORT
mixintemplate EXPORT(alias field, Flags...)

apply Command.exportAs to the command line container

EXPORT_N
mixintemplate EXPORT_N(alias field, Flags...)

apply Command.exportNAs to the command line container

HELP_TEXT_AFTER
mixintemplate HELP_TEXT_AFTER(string text)

add custom help text after command help text

HELP_TEXT_BEFORE
mixintemplate HELP_TEXT_BEFORE(string text)

add custom help text before command help text

HIDE
mixintemplate HIDE(alias field)

hide a registered option from help sub-command and action-option

HIDE
mixintemplate HIDE()

<br><br> hide the command from help sub-command and action-option, usually used on sub-command

NEGATE
mixintemplate NEGATE(alias field, string shortFlag, string desc = "")

set a negate option for a registered option, and its long flag is --no-NAME_OF_OPTION

NO_SUGGESTION
mixintemplate NO_SUGGESTION()

don't show suggestions after parsing error

OPT_TO_ARG
mixintemplate OPT_TO_ARG(Args...)

set the options acting as arguments on command line

PASS_THROUGH
mixintemplate PASS_THROUGH()

allow the command to pass through its option flag behind sub command

PRESET
mixintemplate PRESET(alias field, alias val)

set the preset value to a registered option

RANGE
mixintemplate RANGE(alias field, Args...)

set the range of a registered option or argument which inner type is numeric type

SHOW_HELP_AFTER_ERR
mixintemplate SHOW_HELP_AFTER_ERR()

show help after parsing error

SUB_CMD
mixintemplate SUB_CMD(SubCmds...)

set sub commands

VERSION
mixintemplate VERSION(string ver, string flags = "")

set the version string and enable the version sub-command and action-option

Structs

ArgVal
struct ArgVal(T, bool isOptional = false)

the field of command container which is used to register a argument on the command. the name of it is the name of this argument. can implicitly convert to bool value same as the result of ArgVal.isValid. T is the innerType of the argument, isOptional true to set it optional, default is false.

Choices_d
struct Choices_d(Args...)

used inside the bracket of DEF, DEF_ARG and DEF_OPT to set the choices of an option or an argument

Default_d
struct Default_d(alias val)

used inside the bracket of DEF, DEF_ARG and DEF_OPT to set the default value of an option or an argument

Desc_d
struct Desc_d(alias desc)

used inside the bracket of DEF, DEF_ARG and DEF_OPT to set the desc of an option or an argument

DisableMerge_d
struct DisableMerge_d

used inside the bracket of DEF, DEF_OPT to disable the merge feature of variadic option

Env_d
struct Env_d(alias envKey)

used inside the bracket of DEF, DEF_OPT to set the value from environment of an option

Export_d
struct Export_d(Args...)

used inside the bracket of DEF, DEF_OPT, see EXPORT

Flag_d
struct Flag_d(alias flag)

used inside the bracket of DEF to set the flag of an option

Hide_d
struct Hide_d

used inside the bracket of DEF, DEF_OPT to hide an option from help info

N_Export_d
struct N_Export_d(Args...)

used inside the bracket of DEF, DEF_OPT, see EXPORT_N

Negate_d
struct Negate_d(alias shortFlag, alias desc = "")

used inside the bracket of DEF, DEF_OPT to set the negate option of an option

OptVal
struct OptVal(T, string shortAndVal, bool isMandatory = false)

the field of command container which is used to register a option on the command. the name of it is the name of this option. can implicitly convert to bool value same as the result of ArgVal.isValid. T is the innerType of the option or the elemental type of innerType isMandatory true to set it mandatory, default is false, shortAndVal the short flag and value flag(if needed) seperated by space, comma and |

Optional_d
struct Optional_d

used inside the bracket of DEF to set the option mandatory or set the argument optional

Preset_d
struct Preset_d(alias val)

used inside the bracket of DEF, DEF_OPT to set the preset value of an option

Range_d
struct Range_d(Args...)

used inside the bracket of DEF, DEF_ARG and DEF_OPT to set the range of an option or an argument

ToArg_d
struct ToArg_d

used inside the bracket of DEF, DEF_OPT to make an option act like an argument

Templates

__CMDLINE_getFiledById__
template __CMDLINE_getFiledById__(int id, Types...)
Undocumented in source.

Meta

Authors

笑愚(xiaoyu)