Did you know ... Search Documentation:
Pack execution_context -- prolog/execution_cli.pl
PublicShow source
 execute_cli is det
Same as current_prolog_flag(argv, Arguments), execute_cli(Arguments)
 execute_cli(+Arguments:list(atom)) is det
Interprets Arguments which are assumed to be unified by current_prolog_flag(argv, Arguments) call and calls goal registered by cli_command/2 directive. The name of the command is determined by the first positional argument. Options are removed from the Arguments list by checking against registered context variables - see context_variable/3 predicate.

Throws cli_option(Type, OptionName) exception if required arguments are not provided (see register_cli_command/3), or when the option that cannot be associated with any context variable is found on command line arguments. The exception can be used for print_message call.

 register_cli_command(+Command:atom, :Goal, +ArgumentsSpec:list) is det
Registers new command for CLI. The Goal will be invoked when the first positional argument unifies with Command. The Goal is invoked as call(Goal, PositionalArguments, Options) where PositionalArguments are all arguments that are not an command line option, and Options maps some of the context variables to the goal options. ArgumentSpec can contain some of the following terms:
  • describe(Message) - provides human readable information about the command that is printed when the CLI command help or `command help` is invoked.
  • context(ContextVariable, OptionName) - if call to context_variable_value(ContextVariable, Value) succeeds, then Goal second argument will contain option named OptionName with the value Value. If the context_variable is not resolved then the exception is raised and user informed that the required option is missing
  • optional(context(ContextVariable, OptionName)) - similar to above, but the c ontext variable is not required to be resolved
  • positional(Nth1, OptionName, Describe) - associates Nth1 element of positional arguments with option OptionName when calling Goal. If there are not enough positional argumentsthen the exception is raised and user is informed that argument is missing
  • optional(positional(Nth1, OptionName, Describe)) - similar to above, but the positional argument is not required to be resolved