View Source Tux.Env (Tux v0.4.0)
The environment struct contains the information required by a
dispatcher to execute the logic associated with a given CLI command,
while also being the first argument to be passed to a command module's
Tux.Command.main
callback.
Struct Fields
:raw
- the list of all escript args as typed by the user:cmd
- the command name invoked by the end user which matched against dispatcher's registered command names. (Note that inside a dispatcher, command registration can be achieved using multiple variants: a keyword, a list of keywords, a prefix. – SeeTux.Dispatcher.cmd/2
for more details).:mod
- the command module associated with the given command name.:fun
- the command module callback to execute – .e.g.:main
or:help
. This appropriate function is computed based on the given CLI arguments. For example, when a-h
or--help
flag was provided, the dispatcher will invoke the command module's:help
callback, otherwise the:main
.:arg
- the CLI arguments (minus the command name) to pass to the command module for command execution.:dev
- the IO device where output will be written. (SeeTux.Show
).:pre
- the map with the results from all registered preloads:dsp
- the context/parent dispatcher module.:new
- the boolean flag to add newlines to shown success results.:ext
- theSystem
function to invoke when stopping the VM runtime. The accepted values are:halt
or:stop
.
Summary
Types
Final arguments to pass to the command module's main function
The name of the requested command captured from the CLI args
Device where to print the result
The module within which the env.mod
was registered.
An environment's accepted field name.
The function name of the command module to execute
The module found for the command
A flag which notes if a new line should be written to env device when a {:ok, result} is returned
Preloads executed prior to command main execution
Received arguments from the command line (includes the command string)
The environment contains all the facts necessary for command execution including any warmup artifacts.
An environment's accepted field value.
Functions
Set or update a struct's field, while also performing some type checks to validate if a given value conforms to the struct's specs.
Return a new empty environment struct.
Types
@type arg() :: [String.t()]
Final arguments to pass to the command module's main function
@type cmd() :: :empty | String.t()
The name of the requested command captured from the CLI args
Device where to print the result
@type dsp() :: module()
The module within which the env.mod
was registered.
@type ext() :: :halt | :stop
The function to use on the module System
, when terminating
command execution.
@type field() :: :raw | :cmd | :mod | :fun | :pre | :arg | :dev | :dsp | :new | :ext
An environment's accepted field name.
@type mfn() :: :main | :help
The function name of the command module to execute
@type mod() :: :not_found | module()
The module found for the command
@type new() :: boolean()
A flag which notes if a new line should be written to env device when a {:ok, result} is returned
Preloads executed prior to command main execution
@type raw() :: [String.t()]
Received arguments from the command line (includes the command string)
@type t() :: %Tux.Env{ arg: arg(), cmd: cmd(), dev: dev(), dsp: dsp(), ext: ext(), fun: mfn(), mod: mod(), new: new(), pre: pre(), raw: raw() }
The environment contains all the facts necessary for command execution including any warmup artifacts.
An environment's accepted field value.