summaryrefslogtreecommitdiff
path: root/src/rebar_core.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_core.erl')
-rw-r--r--src/rebar_core.erl41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 4250913..eede6fa 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -51,8 +51,8 @@ run(Args) ->
%% Pre-load the rebar app so that we get default configuration
ok = application:load(rebar),
- OptSpecList = option_spec_list(),
%% Parse getopt options
+ OptSpecList = option_spec_list(),
case getopt:parse(OptSpecList, Args) of
{ok, {_Options, []}} ->
%% no command to run specified
@@ -63,7 +63,7 @@ run(Args) ->
%% display help
getopt:usage(OptSpecList, "rebar");
false ->
- %% set global variables based on getopt options
+ %% Set global variables based on getopt options
set_global_flag(Options, verbose),
set_global_flag(Options, force),
@@ -75,13 +75,17 @@ run(Args) ->
getopt:usage(OptSpecList, "rebar")
end.
-run2(Commands) ->
+run2(Args) ->
%% Make sure crypto is running
crypto:start(),
%% Initialize logging system
rebar_log:init(),
+ %% Filter all the flags (i.e. string of form key=value) from the
+ %% command line arguments. What's left will be the commands to run.
+ Commands = filter_flags(Args, []),
+
%% Convert command strings to atoms
CommandAtoms = [list_to_atom(C) || C <- Commands],
@@ -97,7 +101,12 @@ run2(Commands) ->
%% set global flag based on getopt option boolean value
%%
set_global_flag(Options, Flag) ->
- Value = proplists:get_bool(Flag, Options),
+ Value = case proplists:get_bool(Flag, Options) of
+ true ->
+ "1";
+ false ->
+ "0"
+ end,
rebar_config:set_global(Flag, Value).
%%
@@ -107,10 +116,30 @@ option_spec_list() ->
[
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
{help, $h, "help", undefined, "Show the program options"},
- {verbose, $v, "verbose", {boolean, false}, "Be verbose about what gets done"},
- {force, $f, "force", {boolean, false}, "Force"}
+ {verbose, $v, "verbose", undefined, "Be verbose about what gets done"},
+ {force, $f, "force", undefined, "Force"}
].
+%%
+%% Seperate all commands (single-words) from flags (key=value) and store
+%% values into the rebar_config global storage.
+%%
+filter_flags([], Commands) ->
+ lists:reverse(Commands);
+filter_flags([Item | Rest], Commands) ->
+ case string:tokens(Item, "=") of
+ [Command] ->
+ filter_flags(Rest, [Command | Commands]);
+ [KeyStr, Value] ->
+ Key = list_to_atom(KeyStr),
+ rebar_config:set_global(Key, Value),
+ filter_flags(Rest, Commands);
+ Other ->
+ ?CONSOLE("Ignoring command line argument: ~p\n", [Other]),
+ filter_flags(Rest, Commands)
+ end.
+
+
process_dir(Dir, ParentConfig, Commands) ->
ok = file:set_cwd(Dir),
Config = rebar_config:new(ParentConfig),