Modify module to make it GNU getopt compliant.
Add support for short options with embedded arguments (e.g. -j2).
Add support for implicit boolean options (e.g. -q -> {quiet, true}).
Add support for option terminator ("--").
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
-author('juanjo@comellas.org').
|
||||
|
||||
main([]) ->
|
||||
getopt:usage(option_spec_list(), escript:script_name());
|
||||
usage();
|
||||
main(Args) ->
|
||||
OptSpecList = option_spec_list(),
|
||||
io:format("For command line: ~p~n"
|
||||
@@ -26,16 +26,25 @@ main(Args) ->
|
||||
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")
|
||||
usage(OptSpecList)
|
||||
end.
|
||||
|
||||
|
||||
usage() ->
|
||||
usage(option_spec_list()).
|
||||
|
||||
usage(OptSpecList) ->
|
||||
getopt:usage(OptSpecList, escript:script_name(), "[var1=val1 ...] [command1 ...]",
|
||||
[{"var=value", "Variables that will affect the compilation (e.g. debug=1)"},
|
||||
{"command", "Commands that will be executed by rebar (e.g. compile)"}]).
|
||||
|
||||
|
||||
option_spec_list() ->
|
||||
CpuCount = erlang:system_info(logical_processors),
|
||||
[
|
||||
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
|
||||
{help, $h, "help", undefined, "Show the program options"},
|
||||
{jobs, $j, "jobs", {integer, 1}, "Number of concurrent jobs"},
|
||||
{jobs, $j, "jobs", {integer, CpuCount}, "Number of concurrent jobs"},
|
||||
{verbose, $v, "verbose", {boolean, false}, "Be verbose about what gets done"},
|
||||
{quiet, $q, "quiet", {boolean, false}, "Be quiet about what gets done"},
|
||||
{force, $f, "force", {boolean, false}, "Force"}
|
||||
].
|
||||
|
||||
Reference in New Issue
Block a user