New commands and opts (-V/--version/version/help)

This commit is contained in:
Tuncer Ayaz 2010-05-03 11:38:27 +02:00
parent c319662849
commit 914e5fbf68
2 changed files with 38 additions and 18 deletions

View file

@ -6,11 +6,12 @@ _rebar()
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
sopts="-h -c -v -f -j"
lopts=" --help --commands --verbose --force --jobs="
sopts="-h -c -v -V -f -j"
lopts=" --help --commands --verbose --force --jobs= --version"
cmdsnvars="analyze build_plt check_plt check-deps clean compile \
create create-app create-node delete-deps eunit \
get-deps generate install int_test perf_test test xref \
get-deps generate help install int_test perf_test test \
version xref \
case= force=1 jobs= suite= verbose=1 appid= target= template="
if [[ ${cur} == --* ]] ; then

View file

@ -41,11 +41,13 @@
%% Public API
%% ===================================================================
run(["help"]) ->
help(),
ok;
run(["version"]) ->
%% Load application spec and display vsn and build time info
ok = application:load(rebar),
{ok, Vsn} = application:get_key(rebar, vsn),
?CONSOLE("Version ~s built ~s\n", [Vsn, ?BUILD_TIME]),
version(),
ok;
run(RawArgs) ->
%% Pre-load the rebar app so that we get default configuration
@ -87,7 +89,7 @@ parse_args(Args) ->
case getopt:parse(OptSpecList, Args) of
{ok, {Options, NonOptArgs}} ->
%% Check options and maybe halt execution
{ok, continue} = print_help_maybe_halt(Options, NonOptArgs),
{ok, continue} = show_info_maybe_halt(Options, NonOptArgs),
%% Set global variables based on getopt options
set_global_flag(Options, verbose),
@ -123,26 +125,32 @@ set_global_flag(Options, Flag) ->
rebar_config:set_global(Flag, Value).
%%
%% print help and maybe halt execution
%% show info and maybe halt execution
%%
print_help_maybe_halt(Options, NonOptArgs) ->
case proplists:get_bool(help, Options) of
show_info_maybe_halt(Opts, NonOptArgs) ->
case proplists:get_bool(help, Opts) of
true ->
help(),
halt(0);
false ->
case proplists:get_bool(commands, Options) of
case proplists:get_bool(commands, Opts) of
true ->
commands(),
halt(0);
false ->
case NonOptArgs of
[] ->
io:format("No command to run specified!~n"),
help(),
halt(1);
_ ->
{ok, continue}
case proplists:get_bool(version, Opts) of
true ->
version(),
halt(0);
false ->
case NonOptArgs of
[] ->
?CONSOLE("No command to run specified!~n",[]),
help(),
halt(1);
_ ->
{ok, continue}
end
end
end
end.
@ -187,11 +195,21 @@ perf_test [suite=] [case=] Run ct suites in ./perf_test
test [suite=] [case=] Run ct suites in ./test
xref Run cross reference analysis
help Show the program options
version Show version information
">>,
io:put_chars(S),
%% workaround to delay exit until all output is written
timer:sleep(300).
%%
%% show version information and halt
%%
version() ->
{ok, Vsn} = application:get_key(rebar, vsn),
?CONSOLE("Version ~s built ~s\n", [Vsn, ?BUILD_TIME]).
%%
%% options accepted via getopt
%%
@ -205,6 +223,7 @@ option_spec_list() ->
{help, $h, "help", undefined, "Show the program options"},
{commands, $c, "commands", undefined, "Show available commands"},
{verbose, $v, "verbose", undefined, "Be verbose about what gets done"},
{version, $V, "version", undefined, "Show version information"},
{force, $f, "force", undefined, "Force"},
{jobs, $j, "jobs", integer, JobsHelp}
].
@ -312,7 +331,7 @@ apply_commands([], _Modules, _Config, _ModuleFile) ->
apply_commands([Command | Rest], Modules, Config, ModuleFile) ->
case select_modules(Modules, Command, []) of
[] ->
?CONSOLE("WARNING: ~p command does not apply to directory ~s\n",
?CONSOLE("WARNING: '~p' command does not apply to directory ~s\n",
[Command, rebar_utils:get_cwd()]),
apply_commands(Rest, Modules, Config, ModuleFile);
TargetModules ->