Added example file and make target.
This commit is contained in:
parent
08392f62fe
commit
4c715eaa94
@ -1,2 +1,3 @@
|
|||||||
{"src/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
|
{"src/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
|
||||||
{"src/test/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
|
{"src/test/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
|
||||||
|
{"src/examples/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
|
||||||
|
9
Makefile
9
Makefile
@ -7,16 +7,19 @@ DOC_OPTS={dir, \"doc\"}, {includes, [\"include\"]}, {source_path, [\"include\",
|
|||||||
|
|
||||||
all:
|
all:
|
||||||
@mkdir -p ebin
|
@mkdir -p ebin
|
||||||
$(ERL) $(EPATH) -make
|
@$(ERL) $(EPATH) -make
|
||||||
|
|
||||||
run: all
|
run: all
|
||||||
$(ERL) -sname "$(PROJECT)" $(EPATH)
|
$(ERL) -sname "$(PROJECT)" $(EPATH)
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
$(ERL) -noshell $(EPATH) -s $(PROJECT)_test test -s init stop
|
@$(ERL) -noshell $(EPATH) -s $(PROJECT)_test test -s init stop
|
||||||
|
|
||||||
|
examples: all
|
||||||
|
@$(ERL) -noshell $(EPATH) -s ex1 test -s init stop
|
||||||
|
|
||||||
doc: all
|
doc: all
|
||||||
$(ERL) -noshell $(EPATH) \
|
@$(ERL) -noshell $(EPATH) \
|
||||||
-eval "edoc:files(filelib:wildcard(\"$(SOURCES)\"), [$(DOC_OPTS)])" \
|
-eval "edoc:files(filelib:wildcard(\"$(SOURCES)\"), [$(DOC_OPTS)])" \
|
||||||
-s init stop
|
-s init stop
|
||||||
|
|
||||||
|
78
src/examples/ex1.erl
Normal file
78
src/examples/ex1.erl
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @author Juan Jose Comellas <jcomellas@novamens.com>
|
||||||
|
%%% @copyright (C) 2009, Novamens SA (http://www.novamens.com)
|
||||||
|
%%% @doc Example module for Parses command line options with a format similar to that of GNU getopt.
|
||||||
|
%%% @end
|
||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
-module(ex1).
|
||||||
|
|
||||||
|
-include("include/getopt.hrl").
|
||||||
|
|
||||||
|
-export([test/0, test/1]).
|
||||||
|
|
||||||
|
test() ->
|
||||||
|
test("-U myuser -P mypassword --host myhost -x -o myfile.dump mydb dummy1").
|
||||||
|
|
||||||
|
|
||||||
|
test(CmdLine) ->
|
||||||
|
OptSpecList = option_spec(),
|
||||||
|
|
||||||
|
io:format("For command line: ~p~n"
|
||||||
|
"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]);
|
||||||
|
{error, {Reason, Data}} ->
|
||||||
|
io:format("Error: ~s ~p~n~n", [Reason, Data]),
|
||||||
|
getopt:usage(OptSpecList, "ex1")
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
].
|
Loading…
x
Reference in New Issue
Block a user