Dropped record syntax for the option specifications to simplify use from escripts.
This commit is contained in:
+13
-50
@@ -1,6 +1,6 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author Juan Jose Comellas <jcomellas@novamens.com>
|
||||
%%% @copyright (C) 2009, Novamens SA (http://www.novamens.com)
|
||||
%%% @author Juan Jose Comellas <juanjo@comellas.org>
|
||||
%%% @copyright (C) 2009 Juan Jose Comellas
|
||||
%%% @doc Example file for the getopt module.
|
||||
%%% @end
|
||||
%%%
|
||||
@@ -9,9 +9,7 @@
|
||||
%%% retrieved from: http://www.opensource.org/licenses/bsd-license.php
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(ex1).
|
||||
-author('Juan Jose Comellas <jcomellas@novamens.com>').
|
||||
|
||||
-include("include/getopt.hrl").
|
||||
-author('juanjo@comellas.org').
|
||||
|
||||
-export([test/0, test/1]).
|
||||
|
||||
@@ -26,7 +24,7 @@ test(CmdLine) ->
|
||||
"getopt:parse/2 returns:~n~n", [CmdLine]),
|
||||
case getopt:parse(OptSpecList, CmdLine) of
|
||||
{ok, {Options, NonOptArgs}} ->
|
||||
io:format("Options:~n ~p~nNon-option arguments:~n ~p~n", [Options, NonOptArgs]);
|
||||
io:format("Options:~n ~p~n~nNon-option arguments:~n ~p~n", [Options, NonOptArgs]);
|
||||
{error, {Reason, Data}} ->
|
||||
io:format("Error: ~s ~p~n~n", [Reason, Data]),
|
||||
getopt:usage(OptSpecList, "ex1")
|
||||
@@ -36,48 +34,13 @@ test(CmdLine) ->
|
||||
option_spec() ->
|
||||
CurrentUser = os:getenv("USER"),
|
||||
[
|
||||
#option{name = help,
|
||||
short = $?,
|
||||
long = "help",
|
||||
help = "Show the program options"
|
||||
},
|
||||
#option{name = username,
|
||||
short = $U,
|
||||
long = "username",
|
||||
arg = string,
|
||||
help = "Username to connect to the database"
|
||||
},
|
||||
#option{name = password,
|
||||
short = $P,
|
||||
long = "password",
|
||||
arg = {string, CurrentUser},
|
||||
help = "Password to connect to the database"
|
||||
},
|
||||
#option{name = host,
|
||||
short = $h,
|
||||
long = "host",
|
||||
arg = {string, "localhost"},
|
||||
help = "Database server host name or IP address"
|
||||
},
|
||||
#option{name = port,
|
||||
short = $p,
|
||||
long = "port",
|
||||
arg = {integer, 1000},
|
||||
help = "Database server port"
|
||||
},
|
||||
#option{name = output_file,
|
||||
short = $o,
|
||||
long = "output-file",
|
||||
arg = string,
|
||||
help = "File where the data will be saved to"
|
||||
},
|
||||
#option{name = xml,
|
||||
short = $x,
|
||||
long = "xml",
|
||||
help = "Output data as XML"
|
||||
},
|
||||
#option{name = dbname,
|
||||
arg = string,
|
||||
help = "Database name"
|
||||
}
|
||||
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
|
||||
{help, $?, "help", undefined, "Show the program options"},
|
||||
{username, $U, "username", string, "Username to connect to the database"},
|
||||
{password, $P, "password", {string, CurrentUser}, "Password to connect to the database"},
|
||||
{host, $h, "host", {string, "localhost"}, "Database server host name or IP address"},
|
||||
{port, $p, "port", {integer, 1000}, "Database server port"},
|
||||
{output_file, $o, "output-file", string, "File where the data will be saved to"},
|
||||
{xml, $x, "xml", undefined, "Output data as XML"},
|
||||
{dbname, undefined, undefined, string, "Database name"}
|
||||
].
|
||||
|
||||
Reference in New Issue
Block a user