JustBash.CLI.Command (JustBash v0.4.0)
View SourceA single node in a JustBash.CLI command tree.
A node is either:
- a group — has nested
commandsand norunhandler (it routes to children), or - a leaf — has a
runhandler and no nestedcommands(it does the work).
Build nodes with JustBash.CLI.command/2 rather than constructing the struct directly,
so validation runs.
Fields
:name— the token used to route to this node (e.g."review"):doc— one-line description shown in help output:flags— aJustBash.Commands.ArgParserflag spec (keyword list); leaves only:args— positional argument specs (seearg_spec/0); leaves only:examples— worked examples surfaced in help,describe/1, and docs (seeexample/0):commands— nested child nodes (groups only):run— the handler,(JustBash.CLI.Invocation.t() -> {map(), JustBash.t()}); leaves only:validate— optional(JustBash.CLI.Invocation.t() -> :ok | {:error, String.t()})run after parsing and before:run; an error yields the same exit-2 + usage line as a flag error (leaves only):allow_unknown_flags— whentrue, undeclared flags are collected intoInvocation.extra_flagsinstead of erroring (leaves only):visible?— optional(JustBash.t() -> boolean())predicate; when it returnsfalsethe node is absent (unroutable and omitted from help/describe) for that caller:on_missing_subcommand—:error(default) or:help; what a bare group does when invoked without a subcommand (groups and the root only)
Summary
Types
A positional argument specification.
A worked example, normalized to a map. :cmd is the example invocation; :doc is an
optional one-line description.
Functions
Returns true when the node routes to children rather than running a handler.
Returns true when the node runs a handler.
Types
@type arg_spec() :: %{ :name => atom(), optional(:doc) => String.t(), optional(:required) => boolean(), optional(:variadic) => boolean() }
A positional argument specification.
:name— atom name (also the display label):doc— one-line description:required— whether the argument must be present (defaultfalse):variadic— whentrue, captures all remaining positionals (defaultfalse)
A worked example, normalized to a map. :cmd is the example invocation; :doc is an
optional one-line description.
@type handler() :: (JustBash.CLI.Invocation.t() -> {map(), JustBash.t()})
@type t() :: %JustBash.CLI.Command{ allow_unknown_flags: boolean(), args: [arg_spec()], commands: [t()], doc: String.t() | nil, examples: [example()], flags: keyword(), name: String.t(), on_missing_subcommand: :error | :help, run: handler() | nil, validate: validator() | nil, visible?: visibility() | nil }
@type validator() :: (JustBash.CLI.Invocation.t() -> :ok | {:error, String.t()})
@type visibility() :: (JustBash.t() -> boolean())