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 <: ComoniconExpr
type for positional argument of a command.
Fields
name::String
: name of the argument.type
: type of the argument, defaultAny
.vararg::Bool
: if the argument is a variant argument, defaultfalse
.require::Bool
: if the argument is required, defaulttrue
.default::Maybe{String}
: the default value of this argument if argument is not required (optional), defaultnothing
.description::Description
: the description of this argument, defaultDescription()
.line::Maybe{LineNumberNode}
: the line number of this argument, default isnothing
.
Constructors
Argument(fields_above...)
Argument(;fields_above...)
Comonicon.AST.Color
— Typemutable struct Color
Color configuration.
Fields
name::Symbol
: command name color.args::Symbol
: command args color.dash::Symbol
: command flag/option color.
Comonicon.AST.ComoniconExpr
— Typeabstract type ComoniconExpr end
Abstract type for Comonicon CLI expression.
Comonicon.AST.Description
— Typestruct Description <: ComoniconExpr
type 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 <: ComoniconExpr
Top-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 <: ComoniconExpr
Type 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 assym
but will replace_
with-
.short::Bool
: if this flag support short flag syntax e.g-f
, default isfalse
.description::Description
: description of this flag, default isDescription()
.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 <: ComoniconExpr
Type 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 3
Fields
fn
: a Julia callable that executes the command.name::String
: name of the command.args::Vector{Argument}
: list of CLI arguments, seeArgument
, default isArgument[]
.nrequire::Int
: number of required arguments, default is the number ofrequire==true
arugments inargs
.vararg::Maybe{Argument}
: variant argument, default isnothing
.flags::Dict{String, Flag}
: map between flag name and flag object, seeFlag
, default is the empty collection.options::Dict{String, Option}
: map between option name and option object, seeOption
, default is the empty collection.description::Description
: description of the leaf command, default isDescription()
.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 <: ComoniconExpr
Type 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 3
Fields
name::String
: name of the command.subcmds::Dict{String, Any}
: sub-commands of the node command, this is aname=>command
dict, the command should be eitherNodeCommand
orLeafCommand
.description::Description
: description of this node command, default isDescription()
.line::Maybe{LineNumberNode}
: line number of the node command in its original Julia program, default isnothing
.
Constructors
NodeCommand(fields_above...)
NodeCommand(;fields_above...)
Comonicon.AST.Option
— Typestruct Option <: ComoniconExpr
type 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 assym
but will replace_
with-
.hint::Maybe{String}
: hint message of this option, default isnothing
.require::Bool
: if this option is required, default isfalse
.type
: type of the option value, default isAny
.short::Bool
: if the option support short option syntax (-o<value>
syntax), default isfalse
.description::Description
: description of this option, default isDescription()
.line::Maybe{LineNumberNode}
: line number of this option in Julia scripts.
Comonicon.AST.Terminal
— Typemutable struct Terminal
Configurations for terminal printing.
Fields
Comonicon.AST.print_cmd
— Functionprint_cmd([io::IO], cmd, [terminal::Terminal])
Print the command object in terminal.
Arguments
io::IO
: an IO object, default isstdout
.cmd
: a command object, can beEntry
,NodeCommand
,LeafCommand
.terminal::Terminal
: aTerminal
object, contains the printing and terminal configuration. See alsoTerminal
.
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