ArgumentProcessor.ArgumentProcessor
— ModuleArgumentProcessor
A module to help parse command line arguments and parameters.
ArgumentProcessor.Delimiter
— TypeDelimiter
characters included in discription string. the character can be letter or punctuations below: '=', ' ', '/', ',', ';', ''', '"'
and '%'
ArgumentProcessor.Flag
— TypeFlag
Commandline argument which can be specified but not need to assigned to values, like --argname
or -argabbr
. On other word, it's an argument with logical value. If the variable name exist in commandline input, the value will be set to true
, otherwise to false
contains:
innername
varname which will be the name of variable name after parseoutername
varname which will be displayed and be the input variable nameabbreviation
abbreviation of outernamehelp
help information
ArgumentProcessor.Flag
— MethodFlag(innername::AbstractString; outername::AbstractString="", abbr::AbstractString="", help::AbstractString="")
ArgumentProcessor.Flag
— Method`Flag(d::Dict)`
generate Flag
type from Dict
type. The Dict
must contain keys: "innername"
and optional keys "outername"
, "abbr"
and "help"
ArgumentProcessor.Group
— TypeGroup
A group of Option
and Parameter
.
name
name of the Groupflgs
collect ofFlag
opts
collect ofOption
pars
collect ofParameter
ArgumentProcessor.Group
— MethodGroup(name::AbstractString; flags::Vector{Flag}=Flag[], opts::Vector{Option}=Option[],
pars::Vector{Parameter}=Parameter[])
ArgumentProcessor.Group
— Method`Group(d::Dict)`
generate Group
type from Dict
type. The Dict
must contain keys: "name"
, "flags"
, "opts"
and "pars"
ArgumentProcessor.Option
— TypeOption
Commandline argument which should be assigned to values, usually spicified like --optname=optval
, --optname optval
or -Abbreviation optval
contains:
innername
varname which will be the name of variable name after parseoutername
varname which will be displayed and be the input variable nameabbreviation
abbreviation of outernamedefault
default value (input as string)parsefmt
parse patternrequired
whether throw error when not exist or nothelp
help information
ArgumentProcessor.Option
— MethodOption(innername::AbstractString; outername::AbstractString="", abbr::AbstractString="",
default::AbstractString="", fmt::AbstractString="%s", required::Bool=false, help::AbstractString="")
fmt: C like format discription of input format. The discription is a combination of Varformat
and Delimiter
, and will be appended after the outername. See Varformat
and Delimiter
for more information.
Example
To parse the commandline argument:
program --test=0.1/0.2
The argument is setted like:
Option("test"; fmt="=%f/%f")
ArgumentProcessor.Option
— Method`Option(d::Dict)`
generate Option
type from Dict
type. The Dict
must contain keys: "innername"
and optional keys "outername"
, "abbr"
, "default"
, "format"
, "required"
and "help"
ArgumentProcessor.Parameter
— TypeParameter
Commandline argument which can only be distinguished by position, like program par1 par2
. Different parameters are seperated by space. And other Delimiter
can be used to discribe the input format.
contains:
position
position of the variableinnername
varname which will be the name of variable name after parsedefault
default value (input as string)parsefmt
parse patternrequired
whether throw error when not exist or nothelp
help information
ArgumentProcessor.Parameter
— Method`Parameter(d::Dict)`
generate Parameter
type from Dict
type. The Dict
must contain keys: "position"
and optional keys "innername"
, "abbr"
, "default"
, "format"
, "required"
and "help"
ArgumentProcessor.Parameter
— MethodParameter(position::Int; innername::AbstractString="", default::AbstractString="", fmt::AbstractString="%s",
required::Bool=false, help::AbstractString="")
fmt: C like format discription of input format. The discription is a combination of Varformat
and Delimiter
, and will be appended after the outername. See Varformat
and Delimiter
for more information.
Example
- To parse the commandline argument:
program 0.1
The argument is setted like:
Option(1; fmt="%f")
- commandline argument:
program 2022/01/01T00:00:00.0
setting:
Option(1; fmt="%d/%d/%dT%d:%d:%f")
ArgumentProcessor.Varformat
— TypeVarformat
must be one of:
"%s"
string"%f"/"%g"
decimal float"%c"
complex float"%h"
hexadecimal integer"%o"
octal integer"%b"
binary integer"%d"
integer"%l"
logical (true, false, 0 or 1)
ArgumentProcessor.Dict
— MethodArgumentProcessor._parse
— Method`_parse(str::String, fmt::Vector{FormatPart})`
inner function.
parse string to specified format
ArgumentProcessor.addflag!
— Methodaddflag!(innername::AbstractString; outername::AbstractString="",
abbr::AbstractString="", help::AbstractString="")
ArgumentProcessor.addflag!
— Methodadd a `Flag` type variable to inner buffer
addflag!(f::Flag)
ArgumentProcessor.addopt!
— Methodaddopt!(innername::AbstractString; outername::AbstractString="", abbr::AbstractString="",
default::AbstractString="", fmt::AbstractString="%s", required::Bool=false, help::AbstractString="")
ArgumentProcessor.addopt!
— Methodadd a `Option` type variable to inner buffer
addopt!(a::Option)
ArgumentProcessor.addpar!
— Functionaddpar!(position::Int; innername::AbstractString="", default::AbstractString="", fmt::AbstractString="%s",
required::Bool=false, help::AbstractString="")
ArgumentProcessor.addpar!
— Methodadd a `Parameter` type variable to inner buffer
addpar!(p::Parameter)
ArgumentProcessor.checksetting
— Method`checksetting(grp::Group)`
ArgumentProcessor.checksetting
— Methodchecksetting(grps::Vector{Group})
check if there are conflicts between parameter settings
ArgumentProcessor.clearinnerbuffer!
— Methodclean the inner buffer
clearinnerbuffer!()
ArgumentProcessor.helpstr
— Methodgenerate help string from defined groups
helpstr(groups::Vector{Group})
return value:
(usage_line::String, example_line::String, varname_list::Vector{String},
abbreviation_list::Vector{String}, helps::Vector{String})
ArgumentProcessor.parse
— Methodparse(cmdstr::AbstractString, grps::Vector{Group})
ArgumentProcessor.parse
— Method`parse(line::AbstractString)`
parse commandline input according to inner buffer
ArgumentProcessor.parse
— Methodparse string to defined data structure. If there is `--help`, `--usage` or `-h` in commandline,
the program will print help document and exit.
parse(cmdstr::String, grp::Group)
ArgumentProcessor.parse
— Methodparse(line::Vector{<:AbstractString}, g::Group)
ArgumentProcessor.parse
— Methodparse(line::Vector{<:AbstractString}, g::Vector{Group})
ArgumentProcessor.parse
— Method`parse(lines::Vector{<:AbstractString})`
parse commandline input according to inner buffer
ArgumentProcessor.printhelp
— Functionprint help doc of defined data structure
printhelp(groups::Vector{Group}; programname::AbstractString="", indent::Int=4,
maxabbrcol::Int=5, maxvarcol::Int=10, maxdoccol::Int=60)
ArgumentProcessor.printhelp
— Functionprinthelp(group::Group; programname::AbstractString="", indent::Int=4,
maxabbrcol::Int=5, maxvarcol::Int=30, maxdoccol::Int=60)
ArgumentProcessor.@addflag
— Macro@addflag s
like addflag!
, add a Flag
type variable to inner buffer
ArgumentProcessor.@addopt
— Macro@addopt s
like addopt!
, add a Option
type variable to inner buffer
ArgumentProcessor.@flag_str
— Macro`@flag_str` -> Flag
ArgumentProcessor.@opt_str
— Macro@opt_str -> Option
Create Option
type using input format string