A.30.1 Notes and tips
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(optparse): command line parsing
          • Notes and tips
            • opt_arguments/3
            • opt_parse/4
            • opt_parse/5
            • opt_help/2
            • parse_type/3
    • Packages
Availability::- use_module(library(optparse)).(can be autoloaded)
Source[det]opt_arguments(+OptsSpec, -Opts, -PositionalArgs)
Extract commandline options according to a specification. Convenience predicate, assuming that command-line arguments can be accessed by current_prolog_flag/2 (as in swi-prolog). For other access mechanisms and/or more control, get the args and pass them as a list of atoms to opt_parse/4 or opt_parse/5 instead.

Opts is a list of parsed options in the form Key(Value). Dashed args not in OptsSpec are not permitted and will raise error (see tip on how to pass unknown flags in the module description). PositionalArgs are the remaining non-dashed args after each flag has taken its argument (filling in true or false for booleans). There are no restrictions on non-dashed arguments and they may go anywhere (although it is good practice to put them last). Any leading arguments for the runtime (up to and including’--') are discarded.