summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2010-05-03 11:38:27 +0200
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2010-05-03 11:38:27 +0200
commit914e5fbf68fc87077af4da90d006c12892f59084 (patch)
tree863aedbb2771fa9fa17001ed7d15d78262db02a3
parentc31966284976bfb9f78deb85eb3c1850d085f466 (diff)
New commands and opts (-V/--version/version/help)
-rw-r--r--priv/shell-completion/bash/rebar7
-rw-r--r--src/rebar_core.erl49
2 files changed, 38 insertions, 18 deletions
diff --git a/priv/shell-completion/bash/rebar b/priv/shell-completion/bash/rebar
index 6e089dc..dad06ed 100644
--- a/priv/shell-completion/bash/rebar
+++ b/priv/shell-completion/bash/rebar
@@ -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
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 750cea7..e021fc1 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -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,12 +195,22 @@ 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
%%
option_spec_list() ->
@@ -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 ->