summaryrefslogtreecommitdiff
path: root/src/rebar.erl
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2012-11-10 21:59:19 +0100
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2012-12-31 20:45:11 +0100
commit4b8c81fb53e2caaa74a33d5b62664a67427a7bbf (patch)
tree108c21849e5acf68e0e5f621bc9132a960b6dea7 /src/rebar.erl
parent78fa8fc3d5215e076284b37394e5ca149e945997 (diff)
Implement 'rebar help CMD1 CMD2' and extend common 'rebar help' msg
* allow plugins to print help message for implemented commands * append core rebar.config options to common 'rebar help' message
Diffstat (limited to 'src/rebar.erl')
-rw-r--r--src/rebar.erl56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index c872ade..ded5ebe 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -76,8 +76,18 @@ run(BaseConfig, Commands) ->
%% Internal functions
%% ====================================================================
+run(["help"|RawCmds]) when RawCmds =/= [] ->
+ ok = load_rebar_app(),
+ Cmds = unabbreviate_command_names(RawCmds),
+ Args = parse_args(Cmds),
+ BaseConfig = init_config(Args),
+ {BaseConfig1, _} = save_options(BaseConfig, Args),
+ BaseConfig2 = init_config1(BaseConfig1),
+ rebar_core:help(BaseConfig2, [list_to_atom(C) || C <- Cmds]);
run(["help"]) ->
help();
+run(["info"|_]) ->
+ help();
run(["version"]) ->
ok = load_rebar_app(),
%% Display vsn and build time info
@@ -138,6 +148,16 @@ init_config({Options, _NonOptArgs}) ->
%% Initialize vsn cache
rebar_config:set_xconf(BaseConfig1, vsn_cache, dict:new()).
+init_config1(BaseConfig) ->
+ %% Determine the location of the rebar executable; important for pulling
+ %% resources out of the escript
+ ScriptName = filename:absname(escript:script_name()),
+ BaseConfig1 = rebar_config:set_xconf(BaseConfig, escript, ScriptName),
+ ?DEBUG("Rebar location: ~p\n", [ScriptName]),
+ %% Note the top-level directory for reference
+ AbsCwd = filename:absname(rebar_utils:get_cwd()),
+ rebar_config:set_xconf(BaseConfig1, base_dir, AbsCwd).
+
run_aux(BaseConfig, Commands) ->
%% Make sure crypto is running
case crypto:start() of
@@ -148,18 +168,10 @@ run_aux(BaseConfig, Commands) ->
%% Convert command strings to atoms
CommandAtoms = [list_to_atom(C) || C <- Commands],
- %% Determine the location of the rebar executable; important for pulling
- %% resources out of the escript
- ScriptName = filename:absname(escript:script_name()),
- BaseConfig1 = rebar_config:set_xconf(BaseConfig, escript, ScriptName),
- ?DEBUG("Rebar location: ~p\n", [ScriptName]),
-
- %% Note the top-level directory for reference
- AbsCwd = filename:absname(rebar_utils:get_cwd()),
- BaseConfig2 = rebar_config:set_xconf(BaseConfig1, base_dir, AbsCwd),
+ BaseConfig1 = init_config1(BaseConfig),
%% Process each command, resetting any state between each one
- rebar_core:process_commands(CommandAtoms, BaseConfig2).
+ rebar_core:process_commands(CommandAtoms, BaseConfig1).
%%
%% print help/usage string
@@ -169,7 +181,29 @@ help() ->
getopt:usage(OptSpecList, "rebar",
"[var=value,...] <command,...>",
[{"var=value", "rebar global variables (e.g. force=1)"},
- {"command", "Command to run (e.g. compile)"}]).
+ {"command", "Command to run (e.g. compile)"}]),
+ ?CONSOLE(
+ "Core rebar.config options:~n"
+ " ~p~n"
+ " ~p~n"
+ " ~p~n"
+ " ~p~n"
+ " ~p~n"
+ " ~p~n",
+ [
+ {lib_dirs, []},
+ {sub_dirs, ["dir1", "dir2"]},
+ {plugins, [plugin1, plugin2]},
+ {plugin_dir, "some_other_directory"},
+ {pre_hooks, [{clean, "./prepare_package_files.sh"},
+ {"linux", compile, "c_src/build_linux.sh"},
+ {compile, "escript generate_headers"},
+ {compile, "escript check_headers"}]},
+ {post_hooks, [{clean, "touch file1.out"},
+ {"freebsd", compile, "c_src/freebsd_tweaks.sh"},
+ {eunit, "touch file2.out"},
+ {compile, "touch postcompile.out"}]}
+ ]).
%%
%% Parse command line arguments using getopt and also filtering out any