unix-opts

API Reference

unix-opts

minimalistic parser of command line arguments

UNIX-OPTS

  • Class OPTION
    representation of an option
    NAME   Accessor: NAME
    keyword that will be included in list returned by `get-opts' function if this option is given by user
    DESCRIPTION   Accessor: DESCRIPTION
    description of the option
    SHORT   Accessor: SHORT
    NIL or single char - short variant of the option
    LONG   Accessor: LONG
    NIL or string - long variant of the option
    ARG-PARSER   Accessor: ARG-PARSER
    if not NIL, this option requires an argument, it will be parsed with this function
    META-VAR   Accessor: META-VAR
    if this option requires an argument, this is how it will be printed in option description
  • Condition UNKNOWN-OPTION  (TROUBLESOME-OPTION)
    This condition is thrown when parser encounters unknown (not previously defined with `define-opts') option.
  • Condition MISSING-ARG  (TROUBLESOME-OPTION)
    This condition is thrown when some option OPTION wants an argument, but there is no such argument given.
  • Condition ARG-PARSER-FAILED  (TROUBLESOME-OPTION)
    This condition is thrown when some option OPTION wants an argument, it's given but cannot be parsed by argument parser.
  • Macro DEFINE-OPTS (&body descriptions)
    Define command line options. Arguments of this macro must be plists containing various parameters. Here we enumerate all allowed parameters: :NAME ? keyword that will be included in list returned by GET-OPTS function if actual option is supplied by user. :DESCRIPTION ? description of the option (it will be used in DESCRIBE function). This argument is optional, but it's recommended to supply it. :SHORT ? single character ? short variant of the option. You may omit this argument if you supply :LONG variant of option. :LONG ? string, long variant of option. You may omit this argument if you supply :SHORT variant of option. :ARG-PARSER ? if actual option must take an argument, supply this argument, it must be a function that takes a string and parses it. :META-VAR ? if actual option requires an argument, this is how it will be printed in option description.
  • Function ARGV
    Return list of program's arguments, including command used to execute the program as first elements of the list.
  • Function GET-OPTS (&optional options)
    Parse command line options. If OPTIONS is given, it should be a list to parse. If it's not given, the function will use `argv' function to get list of command line arguments. Return two values: list that contains keywords associated with command line options with `define-opts' macro, and list of free arguments. If some option requires an argument, you can use `getf' to test presence of the option and get its argument if the option is present. The parser may signal various conditions, let's list them all specifying which restarts are available for every condition, and what kind of information the programmer can extract from the conditions. `unknown-option' is thrown when parser encounters unknown (not previously defined with `define-opts') option. Use `option' reader to get name of the option (string). Available restarts: `use-value' (substitute the option and try again), `skip-option' (ignore the option). `missing-arg' is thrown when some option wants an argument, but there is no such argument given. Use `option' reader to get name of the option (string). Available restarts: `use-value' (supplied value will be used), `skip-option' (ignore the option). `arg-parser-failed' is thrown when some option wants an argument, it's given but cannot be parsed by argument parser. Use `option' reader to get name of the option (string) and `raw-arg' to get raw string representing the argument before parsing. Available restarts: `use-value' (supplied value will be used), `skip-option' (ignore the option), `reparse-arg' (supplied string will be parsed instead).
  • Function DESCRIBE (&key prefix suffix usage-of args (stream *standard-output*))
    Return string describing options of the program that were defined with `define-opts' macro previously. You can supply PREFIX and SUFFIX arguments that will be printed before and after options respectively. If USAGE-OF is supplied, it should be a string, name of the program for "Usage: " section. This section is only printed if this name is given. If your program takes arguments (apart from options), you can specify how to print them in "Usage: " section with ARGS option (should be a string designator). Output goes to STREAM.

Also exports

  • COMMON-LISP:USE-VALUE

unix-opts-tests

tests for unix-opts-tests

No packages.