Did you know ... Search Documentation:
Pack execution_context -- prolog/execution_context.pl
PublicShow source
 context_variable(+Name:atom, +Type, +Options:list) is det[multifile]
Declares new contextual variable with the module specific name. Repeated declarations for the same Name are possible, the last call is taken into account but not after the value was queried (which would be served from the cache.

Type can be one of the atom, bool, number, string, list, list(atom), list(number). in case of list types, the list can be specified as a list of atoms or numbers separate by comma (,) or semicolon, and optionally enclosed into parenthesis or brackets (e.g. [ a, b,c, e], or (1;2; 3 ; 4), or o, p ; q, r ) will work. Elements in the list are trimmed of left and right spaces.

Options can be one of:

  • describe(Message) - provides human readable information about the command that is printed when the CLI help is invoked (for cli options).
  • long(Long) - specifies the long name of the command line parameter prefixed with two dashes. If not provided then the Long name is assumed to be based on the name with characters ' ', '_', ':' replaced by the dash. Value of the variable can be either concatenated into argument with '=' character, or separated by space. For example if the long(some_option) is given then the argument `--some-option=value`, or `--some-option value` will both assign value to context variable of the Name.
  • short(Short) - specifies short variant of the command line argument prefixed by '-'. Value must be provided after the space. For example if the option short(s) is given then the argument `-s value` will assign 'value' to context variable of the Name
  • is_flag(Bool) - if Bool is true, then the system recognize the options with out value and `--no-long options, where long` correspnds to the long(Atom) option value. Variables of type bool are implicitly considered to be flags
  • env(EnvName) - specifies the name of the environment variable to check for the value of the context variable. If not provided then the EnvName name is assumed to be based on the name with characters ' ', '_', ':' replaced by the undescore.
  • default(Value) - Specifies the default values if no other means provides a value. If the Value is of the form context(Variable), then context variable Variable is evaluated for the default value. Infinite dependency cycles are not resolved, so be carefull here.
  • cli_command(Commands) - Commands is list of CLI commands (see execute_cli/1), for which the variable is intended. This information is only used to describe usage of the command. Either option short or `long˙, and option `describe˙ must be provided to provide any help information about the variable. The option cli_command([]) is interpreted as the option for all CLI commands.
 context_variable_value(+Variable, -Value) is semidet
Unifies Value with the contextual variable. The Variable must be declared using context_variable/3 call.

To resolve the contextual variable following steps are executed. The first step that succed will determine the Value

  • Check for short or long variant of command line arguments name associated with the variable
  • Check for the environment variable name
  • Check if the Variable name or environment variable name is assigned in the config.user.env file
  • Check if the Variable name or environment variable name is assigned in the config.dev.env file
  • Check if the Variable name or environment variable name is assigned in the config.env file
  • Check if the default value is provided. The config.env files are looked up in the file search paths defined as config(config.env). This module resolves config path to the current working directory or into the config directory of the current working directory. The name variants are provided by the options of the predicate context_variable/2 or derived from the context variable name.
 option_or_context_variable(Option, Options) is semidet
As option/2, but if that fails then it behaves as context_variable(OptionFunctor, OptionArg). Options are checked for the module specific or local name of the option.