Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropped record syntax for the option specifications to simplify use f…
…rom escripts.
- Loading branch information
Juan Jose Comellas
committed
Nov 16, 2009
1 parent
109d9f5
commit 4b03285
Showing
8 changed files
with
270 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
2009-11-16 Juan Jose Comellas <juanjo@comellas.org> | |||
|
|||
* *: Released v0.1 | |||
|
|||
* src/getopt.erl: | |||
* src/test/getopt_test.erl: | |||
* src/examples/ex1.erl: | |||
|
|||
Dropped record syntax for the option specifications to simplify use from escripts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
#!/usr/bin/env escript | |||
%% -*- erlang -*- | |||
%%! -sname ex1 -pz ebin | |||
|
|||
%%%------------------------------------------------------------------- | |||
%%% @author Juan Jose Comellas <juanjo@comellas.org> | |||
%%% @copyright (C) 2009 Juan Jose Comellas | |||
%%% @doc Example file for the getopt module. | |||
%%% @end | |||
%%% | |||
%%% This source file is subject to the New BSD License. You should have received | |||
%%% a copy of the New BSD license with this software. If not, it can be | |||
%%% retrieved from: http://www.opensource.org/licenses/bsd-license.php | |||
%%%------------------------------------------------------------------- | |||
-module(ex1). | |||
-author('juanjo@comellas.org'). | |||
|
|||
main([]) -> | |||
getopt:usage(option_spec_list(), "ex1.escript"); | |||
main(Args) -> | |||
OptSpecList = option_spec_list(), | |||
|
|||
io:format("For command line: ~p~n" | |||
"getopt:parse/2 returns:~n~n", [Args]), | |||
case getopt:parse(OptSpecList, Args) of | |||
{ok, {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.escript") | |||
end. | |||
|
|||
|
|||
option_spec_list() -> | |||
CurrentUser = case os:getenv("USER") of | |||
false -> | |||
"user"; | |||
User -> | |||
User | |||
end, | |||
[ | |||
%% {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"} | |||
]. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.