Command Types
The frontend @main and @cast restrict a lot features to make the package interface as simple as possible. However, if you want to customize the behaviour, you can also create command objects directly via the interfaces at this level, which are all in Comonicon.AST.
References
Comonicon.AST.Argument — Typestruct Argument <: ComoniconExprtype for positional argument of a command.
Fields
- name::String: name of the argument.
- type: type of the argument, default- Any.
- vararg::Bool: if the argument is a variant argument, default- false.
- require::Bool: if the argument is required, default- true.
- default::Maybe{String}: the default value of this argument if argument is not required (optional), default- nothing.
- description::Description: the description of this argument, default- Description().
- line::Maybe{LineNumberNode}: the line number of this argument, default is- nothing.
Constructors
Argument(fields_above...)
Argument(;fields_above...)Comonicon.AST.Color — Typemutable struct ColorColor configuration.
Fields
- name::Symbol: command name color.
- args::Symbol: command args color.
- dash::Symbol: command flag/option color.
Comonicon.AST.ComoniconExpr — Typeabstract type ComoniconExpr endAbstract type for Comonicon CLI expression.
Comonicon.AST.Description — Typestruct Description <: ComoniconExprtype for description of a command object.
Fields
- brief::String: brief introduction of the command, will be printed as the first sentence of the whole description as well as brief intro in upper level help info.
- content::String: long introduction of the command.
Constructors
Description(;brief="", content="")
Description(brief)Comonicon.AST.Entry — Typestruct Entry <: ComoniconExprTop-level entry of the CLI.
Fields
- root::Union{NodeCommand,LeafCommand}: the entry command.
- version::Maybe{VersionNumber}: version number of the command.
- line::Maybe{LineNumberNode}: line number of the original Julia program.
Constructors
Entry(fields_above...)
Entry(;fields_above...)Comonicon.AST.Flag — Typestruct Flag <: ComoniconExprType for flag in CLI, e.g --flag or -f.
Fields
- sym: the symbol in Julia programs.
- name::String: name of the flag, default is the same as- symbut will replace- _with- -.
- short::Bool: if this flag support short flag syntax e.g- -f, default is- false.
- description::Description: description of this flag, default is- Description().
- line::Maybe{LineNumberNode}: the line number of this flag object in original Julia program.
Constructors
Flag(fields_above...)
Flag(;fields_above...)Comonicon.AST.LeafCommand — Typestruct LeafCommand <: ComoniconExprType for a leaf command in CLI. A leaf command is the command that actually execute the program e.g
main-cmd node-cmd leaf-cmd 1 2 3Fields
- fn: a Julia callable that executes the command.
- name::String: name of the command.
- args::Vector{Argument}: list of CLI arguments, see- Argument, default is- Argument[].
- nrequire::Int: number of required arguments, default is the number of- require==truearugments in- args.
- vararg::Maybe{Argument}: variant argument, default is- nothing.
- flags::OrderedDict{String, Flag}: map between flag name and flag object, see- Flag, default is the empty collection.
- options::OrderedDict{String, Option}: map between option name and option object, see- Option, default is the empty collection.
- description::Description: description of the leaf command, default is- Description().
- line::Maybe{LineNumberNode}: line number of the leaf command in original Julia program.
Constructors
LeafCommand(fields_above...)
LeafCommand(;fields_above...)Comonicon.AST.NodeCommand — Typestruct NodeCommand <: ComoniconExprType for node command in a CLI, these command are only used to dispatch the actual command in CLI, and must have sub-command, e.g
main-cmd node-cmd leaf-cmd 1 2 3Fields
- name::String: name of the command.
- subcmds::Dict{String, Any}: sub-commands of the node command, this is a- name=>commanddict, the command should be either- NodeCommandor- LeafCommand.
- description::Description: description of this node command, default is- Description().
- line::Maybe{LineNumberNode}: line number of the node command in its original Julia program, default is- nothing.
Constructors
NodeCommand(fields_above...)
NodeCommand(;fields_above...)Comonicon.AST.Option — Typestruct Option <: ComoniconExprtype for options, e.g --option=<value> or -o<value>.
Fields
- sym::Symbol: symbol of the option in Julia program.
- name::String: name of the option in shell, by default this is the same as- symbut will replace- _with- -.
- hint::Maybe{String}: hint message of this option, default is- nothing.
- require::Bool: if this option is required, default is- false.
- type: type of the option value, default is- Any.
- short::Bool: if the option support short option syntax (- -o<value>syntax), default is- false.
- description::Description: description of this option, default is- Description().
- line::Maybe{LineNumberNode}: line number of this option in Julia scripts.
Comonicon.AST.Terminal — Typemutable struct TerminalConfigurations for terminal printing.
Fields
- width::Int: width of the terminal.
- left::Int: left column max width.
- right::Int: right column max width.
- color:Color: color configurations, see- Color.
- indent::Indent: indent configuration, see- Indent.
- brief::Bool: print the brief intro or not.
Comonicon.AST.print_cmd — Functionprint_cmd([io::IO], cmd, [terminal::Terminal])Print the command object in terminal.
Arguments
- io::IO: an IO object, default is- stdout.
- cmd: a command object, can be- Entry,- NodeCommand,- LeafCommand.
- terminal::Terminal: a- Terminalobject, contains the printing and terminal configuration. See also- Terminal.
Comonicon.AST.splitlines — Functionsplitlines(s, width = 80)Split a given string into lines of width 80 characters.
Comonicon.AST.splittext — Methodsplittext(s)Split the text in string s into an array, but keep all the separators attached to the preceding word.
this is copied from Luxor/text.jl