Module getopt

Parses command line options with a format similar to that of GNU getopt.

Copyright © (C) 2009-2017 Juan Jose Comellas

Authors: Juan Jose Comellas (juanjo@comellas.org).

Description

Parses command line options with a format similar to that of GNU getopt.

Data Types

arg_spec()

arg_spec() = arg_type() | {arg_type(), arg_value()} | undefined

Option type and optional default argument.

arg_type()

arg_type() = atom | binary | utf8_binary | boolean | float | integer | string

Data type that an argument can be converted to.

arg_value()

arg_value() = atom() | binary() | boolean() | float() | integer() | string()

Argument specification.

compound_option()

compound_option() = {atom(), arg_value()}

option()

option() = simple_option() | compound_option()

Command line option specification.

option_spec()

option_spec() = {Name::atom(), Short::char() | undefined, Long::string() | undefined, ArgSpec::arg_spec(), Help::string() | undefined}

Output streams

output_stream()

output_stream() = standard_io | standard_error

simple_option()

simple_option() = atom()

Function Index

check/2Check the parsed command line arguments returning ok if all required options (i.e.
format_error/2Format the error code returned by prior call to parse/2 or check/2.
parse/2Parse the command line options and arguments returning a list of tuples and/or atoms using the Erlang convention for sending options to a function.
parse_and_check/2Parse the command line options and arguments returning a list of tuples and/or atoms using the Erlang convention for sending options to a function.
tokenize/1Tokenize a command line string with support for single and double quoted arguments (needed for arguments that have embedded whitespace).
usage/2 Show a message on standard_error indicating the command line options and arguments that are supported by the program.
usage/3 Show a message on standard_error or standard_io indicating the command line options and arguments that are supported by the program.
usage/4 Show a message on standard_error or standard_io indicating the command line options and arguments that are supported by the program.
usage/6Show a message on standard_error or standard_io indicating the command line options and arguments that are supported by the program.
usage_cmd_line/2
usage_options/1Return a list of help messages to print for each of the options and arguments.

Function Details

check/2

check(OptSpecList::[option_spec()], ParsedOpts::[option()]) -> ok | {error, {Reason::atom(), Option::atom()}}

Check the parsed command line arguments returning ok if all required options (i.e. that don't have defaults) are present, and returning error otherwise.

format_error/2

format_error(OptSpecList::[option_spec()], X2::{error, {Reason, Data}} | {Reason, Data}) -> string()

Format the error code returned by prior call to parse/2 or check/2.

parse/2

parse(OptSpecList::[option_spec()], CmdLine::string() | [string()]) -> {ok, {[option()], [string()]}} | {error, {Reason::atom(), Data::term()}}

Parse the command line options and arguments returning a list of tuples and/or atoms using the Erlang convention for sending options to a function.

parse_and_check/2

parse_and_check(OptSpecList::[option_spec()], CmdLine::string() | [string()]) -> {ok, {[option()], [string()]}} | {error, {Reason::atom(), Data::term()}}

Parse the command line options and arguments returning a list of tuples and/or atoms using the Erlang convention for sending options to a function. Additionally perform check if all required options (the ones without default values) are present. The function is a combination of two calls: parse/2 and check/2.

tokenize/1

tokenize(CmdLine::string()) -> [nonempty_string()]

Tokenize a command line string with support for single and double quoted arguments (needed for arguments that have embedded whitespace). The function also supports the expansion of environment variables in both the Unix (${VAR}; $VAR) and Windows (%VAR%) formats. It does NOT support wildcard expansion of paths.

usage/2

usage(OptSpecList::[option_spec()], ProgramName::string()) -> ok

Show a message on standard_error indicating the command line options and arguments that are supported by the program.

usage/3

usage(OptSpecList::[option_spec()], ProgramName::string(), OutputStream::output_stream() | string()) -> ok

Show a message on standard_error or standard_io indicating the command line options and arguments that are supported by the program.

usage/4

usage(OptSpecList::[option_spec()], ProgramName::string(), CmdLineTail::string(), OutputStream::output_stream() | [{string(), string()}]) -> ok

Show a message on standard_error or standard_io indicating the command line options and arguments that are supported by the program. The CmdLineTail argument is a string that is added to the end of the usage command line.

usage/6

usage(OptSpecList::[option_spec()], ProgramName::string(), CmdLineTail::string(), Description::string(), OptionsTail::[{OptionName::string(), Help::string()}], OutputStream::output_stream()) -> ok

Show a message on standard_error or standard_io indicating the command line options and arguments that are supported by the program. The Description allows for structured command line usage that works in addition to the standard options, and appears between the usage_cmd_line and usage_options sections. The CmdLineTail and OptionsTail arguments are a string that is added to the end of the usage command line and a list of tuples that are added to the end of the options' help lines.

usage_cmd_line/2

usage_cmd_line(ProgramName::string(), OptSpecList::[option_spec()]) -> iolist()

usage_options/1

usage_options(OptSpecList::[option_spec()]) -> [string()]

Return a list of help messages to print for each of the options and arguments.


Generated by EDoc