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.ArgumentType
struct Argument <: ComoniconExpr

type 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...)
source
Comonicon.AST.ColorType
mutable struct Color

Color configuration.

Fields

  • name::Symbol: command name color.
  • args::Symbol: command args color.
  • dash::Symbol: command flag/option color.
source
Comonicon.AST.DescriptionType
struct 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)
source
Comonicon.AST.EntryType
struct 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...)
source
Comonicon.AST.FlagType
struct 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 as sym but 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...)
source
Comonicon.AST.LeafCommandType
struct 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, see Argument, default is Argument[].
  • nrequire::Int: number of required arguments, default is the number of require==true arugments 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...)
source
Comonicon.AST.NodeCommandType
struct 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 a name=>command dict, the command should be either NodeCommand or 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...)
source
Comonicon.AST.OptionType
struct 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 as sym but 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.
source
Comonicon.AST.TerminalType
mutable struct Terminal

Configurations 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.
source
Comonicon.AST.print_cmdFunction
print_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 Terminal object, contains the printing and terminal configuration. See also Terminal.
source
Comonicon.AST.splittextMethod
splittext(s)

Split the text in string s into an array, but keep all the separators attached to the preceding word.

Note

this is copied from Luxor/text.jl

source