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. – See Tux.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. (See Tux.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 - the System 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.

The function to use on the module System, when terminating command execution.

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)

t()

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

arg()

@type arg() :: [String.t()]

Final arguments to pass to the command module's main function

cmd()

@type cmd() :: :empty | String.t()

The name of the requested command captured from the CLI args

dev()

@type dev() :: atom() | pid()

Device where to print the result

dsp()

@type dsp() :: module()

The module within which the env.mod was registered.

ext()

@type ext() :: :halt | :stop

The function to use on the module System, when terminating command execution.

field()

@type field() :: :raw | :cmd | :mod | :fun | :pre | :arg | :dev | :dsp | :new | :ext

An environment's accepted field name.

mfn()

@type mfn() :: :main | :help

The function name of the command module to execute

mod()

@type mod() :: :not_found | module()

The module found for the command

new()

@type new() :: boolean()

A flag which notes if a new line should be written to env device when a {:ok, result} is returned

pre()

@type pre() :: %{required(atom()) => any()}

Preloads executed prior to command main execution

raw()

@type raw() :: [String.t()]

Received arguments from the command line (includes the command string)

t()

@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.

value()

@type value() ::
  raw() | cmd() | mod() | mfn() | pre() | arg() | dev() | dsp() | new() | ext()

An environment's accepted field value.

Functions

add(env, atom, raw)

@spec add(t(), field(), value()) :: t()

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.

new()

Return a new empty environment struct.