Fix README format
This commit is contained in:
parent
3f0ac07896
commit
08931e2394
70
README.md
70
README.md
@ -36,15 +36,15 @@ Usage
|
||||
The *getopt* module provides four functions:
|
||||
|
||||
``` erlang
|
||||
parse([{Name, Short, Long, ArgSpec, Help}], Args :: string() | [string()]) ->
|
||||
parse([{Name, Short, Long, ArgSpec, Help}], Args :: string() | [string()]) ->
|
||||
{ok, {Options, NonOptionArgs}} | {error, {Reason, Data}}
|
||||
|
||||
usage([{Name, Short, Long, ArgSpec, Help}], ProgramName :: string()) -> ok
|
||||
usage([{Name, Short, Long, ArgSpec, Help}], ProgramName :: string()) -> ok
|
||||
|
||||
usage([{Name, Short, Long, ArgSpec, Help}], ProgramName :: string(),
|
||||
usage([{Name, Short, Long, ArgSpec, Help}], ProgramName :: string(),
|
||||
CmdLineTail :: string()) -> ok
|
||||
|
||||
usage([{Name, Short, Long, ArgSpec, Help}], ProgramName :: string(),
|
||||
usage([{Name, Short, Long, ArgSpec, Help}], ProgramName :: string(),
|
||||
CmdLineTail :: string(), OptionsTail :: [{string(), string}]) -> ok
|
||||
```
|
||||
|
||||
@ -52,13 +52,13 @@ The ``parse/2`` function receives a list of tuples with the command line option
|
||||
specifications. The type specification for the tuple is:
|
||||
|
||||
``` erlang
|
||||
-type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' | 'string'.
|
||||
-type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' | 'string'.
|
||||
|
||||
-type arg_value() :: atom() | binary() | boolean() | float() | integer() | string().
|
||||
-type arg_value() :: atom() | binary() | boolean() | float() | integer() | string().
|
||||
|
||||
-type arg_spec() :: arg_type() | {arg_type(), arg_value()} | undefined.
|
||||
-type arg_spec() :: arg_type() | {arg_type(), arg_value()} | undefined.
|
||||
|
||||
-type option_spec() :: {
|
||||
-type option_spec() :: {
|
||||
Name :: atom(),
|
||||
Short :: char() | undefined,
|
||||
Long :: string() | undefined,
|
||||
@ -78,7 +78,7 @@ The elements of the tuple are:
|
||||
e.g.
|
||||
|
||||
``` erlang
|
||||
{port, $p, "port", {integer, 5432}, "Database server port"}
|
||||
{port, $p, "port", {integer, 5432}, "Database server port"}
|
||||
```
|
||||
|
||||
The second parameter receives the list of arguments as passed to the ``main/1``
|
||||
@ -96,7 +96,7 @@ all the arguments that did not have corresponding options.
|
||||
e.g. Given the following option specifications:
|
||||
|
||||
``` erlang
|
||||
OptSpecList =
|
||||
OptSpecList =
|
||||
[
|
||||
{host, $h, "host", {string, "localhost"}, "Database server host"},
|
||||
{port, $p, "port", integer, "Database server port"},
|
||||
@ -110,25 +110,25 @@ e.g. Given the following option specifications:
|
||||
And this command line:
|
||||
|
||||
``` erlang
|
||||
Args = "-h myhost --port=1000 -x myfile.txt -vvv dummy1 dummy2"
|
||||
Args = "-h myhost --port=1000 -x myfile.txt -vvv dummy1 dummy2"
|
||||
```
|
||||
|
||||
Which could also be passed in the format the ``main/1`` function receives the arguments in escripts:
|
||||
|
||||
``` erlang
|
||||
Args = ["-h", "myhost", "--port=1000", "-x", "file.txt", "-vvv", "dummy1", "dummy2"].
|
||||
Args = ["-h", "myhost", "--port=1000", "-x", "file.txt", "-vvv", "dummy1", "dummy2"].
|
||||
```
|
||||
|
||||
The call to ``getopt:parse/2``:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, Args).
|
||||
getopt:parse(OptSpecList, Args).
|
||||
```
|
||||
|
||||
Will return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{host,"myhost"},
|
||||
{ok,{[{host,"myhost"},
|
||||
{port,1000},
|
||||
xml,
|
||||
{file,"file.txt"},
|
||||
@ -143,7 +143,7 @@ For example, given the above-mentioned option specifications, the call to
|
||||
``getopt:usage/2``:
|
||||
|
||||
``` erlang
|
||||
getopt:usage(OptSpecList, "ex1").
|
||||
getopt:usage(OptSpecList, "ex1").
|
||||
```
|
||||
|
||||
Will show (on *standard_error*):
|
||||
@ -159,7 +159,9 @@ Will show (on *standard_error*):
|
||||
|
||||
This call to ``getopt:usage/3`` will add a string after the usage command line:
|
||||
|
||||
``` erlang
|
||||
getopt:usage(OptSpecList, "ex1", "[var=value ...] [command ...]").
|
||||
```
|
||||
|
||||
Will show (on *standard_error*):
|
||||
|
||||
@ -176,7 +178,7 @@ Whereas this call to ``getopt:usage/3`` will also add some lines to the options
|
||||
help text:
|
||||
|
||||
``` erlang
|
||||
getopt:usage(OptSpecList, "ex1", "[var=value ...] [command ...]",
|
||||
getopt:usage(OptSpecList, "ex1", "[var=value ...] [command ...]",
|
||||
[{"var=value", "Variables that will affect the execution (e.g. debug=1)"},
|
||||
{"command", "Commands that will be executed (e.g. count)"}]).
|
||||
```
|
||||
@ -255,7 +257,7 @@ number that will be returned for that specific option.
|
||||
e.g. Given an option specification list with the following format:
|
||||
|
||||
``` erlang
|
||||
OptSpecList =
|
||||
OptSpecList =
|
||||
[
|
||||
{define, $D, "define", string, "Define a variable"},
|
||||
{verbose, $v, "verbose", integer, "Verbosity level"}
|
||||
@ -265,13 +267,13 @@ e.g. Given an option specification list with the following format:
|
||||
The following invocation:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, "-DFOO -DVAR1=VAL1 -DBAR --verbose --verbose=3 -v -vvvv dummy").
|
||||
getopt:parse(OptSpecList, "-DFOO -DVAR1=VAL1 -DBAR --verbose --verbose=3 -v -vvvv dummy").
|
||||
```
|
||||
|
||||
would return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{define,"FOO"}, {define,"VAR1=VAL1"}, {define,"BAR"},
|
||||
{ok,{[{define,"FOO"}, {define,"VAR1=VAL1"}, {define,"BAR"},
|
||||
{verbose,1}, {verbose,3}, {verbose,1}, {verbose,4}],
|
||||
["dummy"]}}
|
||||
```
|
||||
@ -287,7 +289,7 @@ list passed to ``getopt:/parse2``.
|
||||
For example, with the following option specifications:
|
||||
|
||||
``` erlang
|
||||
OptSpecList =
|
||||
OptSpecList =
|
||||
[
|
||||
{xml, $x, "xml", undefined, "Output data as XML"},
|
||||
{dbname, undefined, undefined, string, "Database name"},
|
||||
@ -298,13 +300,13 @@ For example, with the following option specifications:
|
||||
This call to ``getopt:parse/2``:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, "-x mydb file.out dummy dummy").
|
||||
getopt:parse(OptSpecList, "-x mydb file.out dummy dummy").
|
||||
```
|
||||
|
||||
Will return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[xml,{dbname,"mydb"},{output_file,"file.out"}],
|
||||
{ok,{[xml,{dbname,"mydb"},{output_file,"file.out"}],
|
||||
["dummy","dummy"]}}
|
||||
```
|
||||
|
||||
@ -319,13 +321,13 @@ returned without being evaluated even if they follow the *getopt* syntax.
|
||||
e.g. This invocation using the first option specification list in the document:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, "-h myhost -p 1000 -- --dbname mydb dummy").
|
||||
getopt:parse(OptSpecList, "-h myhost -p 1000 -- --dbname mydb dummy").
|
||||
```
|
||||
|
||||
will return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{host,"myhost"}, {port,1000},{dbname,"users"}],
|
||||
{ok,{[{host,"myhost"}, {port,1000},{dbname,"users"}],
|
||||
["--dbname","mydb","dummy"]}}
|
||||
```
|
||||
|
||||
@ -342,13 +344,13 @@ The single ``-`` character is always considered as a non-option argument.
|
||||
e.g. This invocation using the specification list from the previous example:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, "-h myhost -p 1000 - --dbname mydb dummy").
|
||||
getopt:parse(OptSpecList, "-h myhost -p 1000 - --dbname mydb dummy").
|
||||
```
|
||||
|
||||
will return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{host,"myhost"}, {port,1000}, {dbname,"mydb"}],
|
||||
{ok,{[{host,"myhost"}, {port,1000}, {dbname,"mydb"}],
|
||||
["-","dummy"]}}
|
||||
```
|
||||
|
||||
@ -364,7 +366,7 @@ argument.
|
||||
e.g. Given an option specification list with the following format:
|
||||
|
||||
``` erlang
|
||||
OptSpecList =
|
||||
OptSpecList =
|
||||
[
|
||||
{define, $D, "define", string, "Define a variable"},
|
||||
{user, $u, "user", string, "User name"}
|
||||
@ -374,14 +376,14 @@ e.g. Given an option specification list with the following format:
|
||||
The following invocation:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList,
|
||||
getopt:parse(OptSpecList,
|
||||
"-D'FOO=VAR 123' --define \"VAR WITH SPACES\" -u\"my user name\"").
|
||||
```
|
||||
|
||||
would return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{define,"FOO=VAR 123"},
|
||||
{ok,{[{define,"FOO=VAR 123"},
|
||||
{define,"VAR WITH SPACES"},
|
||||
{user,"my user name"}],
|
||||
[]}}
|
||||
@ -394,13 +396,13 @@ was entered.
|
||||
e.g. The following invocation:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, "--user ' my user ' \"argument with unclosed quotes").
|
||||
getopt:parse(OptSpecList, "--user ' my user ' \"argument with unclosed quotes").
|
||||
```
|
||||
|
||||
would return:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{user," my user "}],
|
||||
{ok,{[{user," my user "}],
|
||||
["argument with unclosed quotes"]}}
|
||||
```
|
||||
|
||||
@ -424,7 +426,7 @@ single-quoted arguments.
|
||||
e.g. Given the following option specification list:
|
||||
|
||||
``` erlang
|
||||
OptSpecList =
|
||||
OptSpecList =
|
||||
[
|
||||
{path, $p, "path", string, "File path"}
|
||||
].
|
||||
@ -433,13 +435,13 @@ e.g. Given the following option specification list:
|
||||
The following invocation:
|
||||
|
||||
``` erlang
|
||||
getopt:parse(OptSpecList, "--path ${PATH} $NONEXISTENT_DUMMY_VAR").
|
||||
getopt:parse(OptSpecList, "--path ${PATH} $NONEXISTENT_DUMMY_VAR").
|
||||
```
|
||||
|
||||
would return (depending on the value of your PATH variable) something like:
|
||||
|
||||
``` erlang
|
||||
{ok,{[{path, "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}],
|
||||
{ok,{[{path, "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}],
|
||||
["$NONEXISTENT_DUMMY_VAR"]}}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user