Did you know ... Search Documentation:
Pack prolog_library_collection -- prolog/cli.pl
PublicShow source

This module can be used to build a CLI tool with minimal custom code.

The predicate cli_main/4 takes:

  1. the name of the tool,
  2. usage specifications (positional arguments),
  3. flag specifications (flag arguments), and
  4. the tool's main goal.

It takes care of the common flags -h/`--help and -v/--version`.

The following three types of command-line argument can be distinguised:

  • Runtime arguments Should be handled by the Prolog runtime, and are therefore not handled by this module. Runtime arguments must appear before other arguments, and not be separated from other arguments by --.
  • Flag arguments Key-value pairs (with a boolean value possibly implicit) intended to control your program in one way or another.
  • Positional arguments What remains after all runtime arguments and options have been removed (with implicit arguments ― true/false for booleans ― filled in).
 cli_main(+Name:atom, +Usages:list(list(atom)), :Goal_2) is det
 cli_main(+Name:atom, +Usages:list(list(atom)), +Specs:list(dict), :Goal_2) is det