From 940f9c232ba6c2896991d83ed8c5e296e470c5a0 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 31 Dec 2009 18:00:02 +0100 Subject: Enhanced option parsing with new getopt and made rebar more user friendly --- src/getopt.erl | 146 +++++++++++++++++++++++++++++++++++++++----------- src/rebar_config.erl | 7 +-- src/rebar_core.erl | 53 +++++------------- src/rebar_ct.erl | 8 +-- src/rebar_log.erl | 4 +- src/rebar_otp_app.erl | 6 +-- src/rebar_reltool.erl | 4 +- 7 files changed, 141 insertions(+), 87 deletions(-) diff --git a/src/getopt.erl b/src/getopt.erl index b335f0c..edc8f3f 100644 --- a/src/getopt.erl +++ b/src/getopt.erl @@ -11,6 +11,9 @@ -module(getopt). -author('juanjo@comellas.org'). +-export([parse/2, usage/2]). + + -define(TAB_LENGTH, 8). %% Indentation of the help messages in number of tabs. -define(INDENTATION, 3). @@ -44,8 +47,6 @@ Help :: string() | undefined }. --export([parse/2, usage/2]). - -spec parse([option_spec()], string() | [string()]) -> {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data :: any()}}. %%-------------------------------------------------------------------- @@ -71,12 +72,20 @@ parse(OptSpecList, CmdLine) -> -spec parse([option_spec()], [option()], [string()], integer(), [string()]) -> {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data:: any()}}. %% Process long options. -parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | LongName] = OptStr | Tail]) -> - {Option, Tail1} = get_option(OptSpecList, OptStr, LongName, ?OPT_LONG, Tail), +parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | Name] = OptStr | Tail]) -> + {Option, Tail1} = + case split_embedded_arg(Name) of + {Name1, Arg} -> + %% Get option that has its argument within the same string + %% separated by an equal ('=') character. + {get_option_embedded_arg(OptSpecList, OptStr, ?OPT_LONG, Name1, Arg), Tail}; + _Name1 -> + get_option(OptSpecList, OptStr, ?OPT_LONG, Name, Tail) + end, parse(OptSpecList, [Option | OptAcc], ArgAcc, ArgPos, Tail1); %% Process short options. parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, ShortName] = OptStr | Tail]) -> - {Option, Tail1} = get_option(OptSpecList, OptStr, ShortName, ?OPT_SHORT, Tail), + {Option, Tail1} = get_option(OptSpecList, OptStr, ?OPT_SHORT, ShortName, Tail), parse(OptSpecList, [Option | OptAcc], ArgAcc, ArgPos, Tail1); %% Process multiple short options with no argument. parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | ShortNameList] = OptStr | Tail]) -> @@ -87,12 +96,21 @@ parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | ShortNameList] = OptStr | Tail end, OptAcc, ShortNameList), parse(OptSpecList, NewOptAcc, ArgAcc, ArgPos, Tail); %% Process non-option arguments. -parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) -> - case find_non_option_arg(OptSpecList, ArgPos) of - {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) -> - parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], ArgAcc, ArgPos + 1, Tail); - false -> - parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail) +parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [OptStr | Tail]) -> + case split_embedded_arg(OptStr) of + {Name, Arg} -> + %% Get option that has its argument within the same string + %% separated by an equal ('=') character. + parse(OptSpecList, [get_option_embedded_arg(OptSpecList, OptStr, ?OPT_LONG, Name, Arg) | OptAcc], + ArgAcc, ArgPos, Tail); + Arg -> + case find_non_option_arg(OptSpecList, ArgPos) of + {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) -> + parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], + ArgAcc, ArgPos + 1, Tail); + false -> + parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail) + end end; parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) -> %% Once we have completed gathering the options we add the ones that were @@ -100,28 +118,75 @@ parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) -> {ok, {lists:reverse(append_default_args(OptSpecList, OptAcc)), lists:reverse(ArgAcc)}}. --spec get_option([option_spec()], string(), string() | char(), integer(), [string()]) -> +-spec get_option([option_spec()], string(), integer(), string() | char(), [string()]) -> {option(), [string()]}. %% @doc Retrieve the specification corresponding to an option matching a string %% received on the command line. -get_option(OptSpecList, OptStr, OptName, FieldPos, Tail) -> +get_option(OptSpecList, OptStr, FieldPos, OptName, Tail) -> case lists:keysearch(OptName, FieldPos, OptSpecList) of {value, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec} -> case ArgSpec of undefined -> {Name, Tail}; _ -> + ArgSpecType = arg_spec_type(ArgSpec), case Tail of [Arg | Tail1] -> - {convert_option_arg(OptSpec, Arg), Tail1}; - [] -> - throw({error, {missing_option_arg, Name}}) + case (ArgSpecType =:= boolean) andalso not is_boolean_arg(Arg) of + %% Special case for booleans: when the next string + %% is an option we assume the value is 'true'. + true -> + {{Name, true}, Tail}; + _ -> + {convert_option_arg(OptSpec, Arg), Tail1} + end; + [] -> + case ArgSpecType of + boolean -> + {{Name, true}, Tail}; + _ -> + throw({error, {missing_option_arg, Name}}) + end end end; false -> throw({error, {invalid_option, OptStr}}) end. + +-spec get_option_embedded_arg([option_spec()], string(), integer(), string(), + string()) -> option(). +%% @doc Retrieve the specification corresponding to an option matching a string +%% received on the command line that had its argument assigned within the +%% same string (e.g. "verbose=true"). +get_option_embedded_arg(OptSpecList, OptStr, FieldPos, OptName, Arg) -> + case lists:keysearch(OptName, FieldPos, OptSpecList) of + {value, {_Name, _Short, _Long, ArgSpec, _Help} = OptSpec} -> + case ArgSpec of + undefined -> + throw({error, {invalid_option_arg, OptStr}}); + _ -> + convert_option_arg(OptSpec, Arg) + end; + false -> + throw({error, {invalid_option, OptStr}}) + end. + + +-spec split_embedded_arg(string()) -> {Name :: string(), Arg :: string()} | string(). +%% @doc Split an option string that may contain and option with its argument +%% separated by an equal ('=') character (e.g. "port=1000"). +split_embedded_arg(OptStr) -> + split_embedded_arg(OptStr, OptStr, []). + +split_embedded_arg(_OptStr, [$= | Tail], Acc) -> + {lists:reverse(Acc), Tail}; +split_embedded_arg(OptStr, [Char | Tail], Acc) -> + split_embedded_arg(OptStr, Tail, [Char | Acc]); +split_embedded_arg(OptStr, [], _Acc) -> + OptStr. + + -spec get_option_no_arg([option_spec()], string(), string() | char(), integer()) -> option(). %% @doc Retrieve the specification corresponding to an option that has no %% argument and matches a string received on the command line. @@ -129,12 +194,20 @@ get_option_no_arg(OptSpecList, OptStr, OptName, FieldPos) -> case lists:keysearch(OptName, FieldPos, OptSpecList) of {value, {Name, _Short, _Long, undefined, _Help}} -> Name; - {value, {Name, _Short, _Long, _ArgSpec, _Help}} -> - throw({error, {missing_option_arg, Name}}); + {value, {Name, _Short, _Long, ArgSpec, _Help}} -> + case arg_spec_type(ArgSpec) of + %% Special case for booleans: if there is no argument we assume + %% the value is 'true'. + boolean -> + {Name, true}; + _ -> + throw({error, {missing_option_arg, Name}}) + end; false -> throw({error, {invalid_option, OptStr}}) end. + -spec find_non_option_arg([option_spec()], integer()) -> {value, option_spec()} | false. %% @doc Find the option for the discrete argument in position specified in the %% Pos argument. @@ -165,23 +238,30 @@ append_default_args([], OptAcc) -> OptAcc. +%% -spec is_option(string()) -> boolean(). +%% is_option([Char | _Tail] = OptStr) -> +%% (Char =:= $-) orelse lists:member($=, OptStr). + + -spec convert_option_arg(option_spec(), string()) -> [option()]. %% @doc Convert the argument passed in the command line to the data type -%% indicated byt the argument specification. +%% indicated by the argument specification. convert_option_arg({Name, _Short, _Long, ArgSpec, _Help}, Arg) -> try - Converted = case ArgSpec of - {Type, _DefaultArg} -> - to_type(Type, Arg); - Type when is_atom(Type) -> - to_type(Type, Arg) - end, - {Name, Converted} + {Name, to_type(arg_spec_type(ArgSpec), Arg)} catch error:_ -> throw({error, {invalid_option_arg, {Name, Arg}}}) end. + +-spec arg_spec_type(arg_spec()) -> arg_type() | undefined. +arg_spec_type({Type, _DefaultArg}) -> + Type; +arg_spec_type(Type) when is_atom(Type) -> + Type. + + -spec to_type(atom(), string()) -> arg_value(). to_type(binary, Arg) -> list_to_binary(Arg); @@ -192,14 +272,20 @@ to_type(integer, Arg) -> to_type(float, Arg) -> list_to_float(Arg); to_type(boolean, Arg) -> - LowerArg = string:to_lower(Arg), - (LowerArg =:= "true") orelse (LowerArg =:= "t") orelse - (LowerArg =:= "yes") orelse (LowerArg =:= "y") orelse - (LowerArg =:= "on") orelse (LowerArg =:= "enabled"); + is_boolean_arg(Arg); to_type(_Type, Arg) -> Arg. +-spec is_boolean_arg(string()) -> boolean(). +is_boolean_arg(Arg) -> + LowerArg = string:to_lower(Arg), + (LowerArg =:= "true") orelse (LowerArg =:= "t") orelse + (LowerArg =:= "yes") orelse (LowerArg =:= "y") orelse + (LowerArg =:= "on") orelse (LowerArg =:= "enabled") orelse + (LowerArg =:= "1"). + + -spec usage([option_spec()], string()) -> ok. %%-------------------------------------------------------------------- %% @spec usage(OptSpecList :: option_spec_list(), ProgramName :: string()) -> ok. diff --git a/src/rebar_config.erl b/src/rebar_config.erl index 29246c9..33bef58 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -81,12 +81,7 @@ get_global(Key, Default) -> end. is_verbose() -> - case get_global(verbose, "0") of - "1" -> - true; - _ -> - false - end. + get_global(verbose, false). %% =================================================================== diff --git a/src/rebar_core.erl b/src/rebar_core.erl index b938b4b..a40419a 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -49,17 +49,20 @@ run(Args) -> %% Pre-load the rebar app so that we get default configuration ok = application:load(rebar), + OptSpecList = option_spec_list(), %% Parse getopt options - case getopt:parse(option_spec_list(), Args) of + case getopt:parse(OptSpecList, Args) of + {ok, {_Options, []}} -> + %% no command to run specified + getopt:usage(OptSpecList, "rebar"); {ok, {Options, NonOptArgs}} -> case proplists:get_bool(help, Options) of true -> - %% display usage info - getopt:usage(option_spec_list(), "rebar"); + %% 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, quiet), set_global_flag(Options, force), %% run rebar with supplied options @@ -67,20 +70,16 @@ run(Args) -> end; {error, {Reason, Data}} -> ?ERROR("Error: ~s ~p~n~n", [Reason, Data]), - getopt:usage(option_spec_list(), "rebar") + getopt:usage(OptSpecList, "rebar") end. -run2(Args) -> +run2(Commands) -> %% 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], @@ -96,12 +95,7 @@ run2(Args) -> %% set global flag based on getopt option boolean value %% set_global_flag(Options, Flag) -> - Value = case proplists:get_bool(Flag, Options) of - true -> - "1"; - false -> - "0" - end, + Value = proplists:get_bool(Flag, Options), rebar_config:set_global(Flag, Value). %% @@ -111,31 +105,10 @@ option_spec_list() -> [ %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} {help, $h, "help", undefined, "Show the program options"}, - {verbose, $v, "verbose", undefined, "Be verbose about what gets done"}, - {quiet, $q, "quiet", undefined, "Be quiet about what gets done"}, - {force, $f, "force", undefined, "Force"} + {verbose, $v, "verbose", {boolean, false}, "Be verbose about what gets done"}, + {force, $f, "force", {boolean, false}, "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), diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 41487ab..9cc05a1 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -71,8 +71,8 @@ run_test_if_present(TestDir, Config, File) -> run_test(TestDir, Config, _File) -> {Cmd, RawLog} = make_cmd(TestDir, Config), clear_log(RawLog), - case rebar_config:get_global(verbose, "0") of - "0" -> + case rebar_config:is_verbose() of + true -> Output = " >> " ++ RawLog ++ " 2>&1"; _ -> Output = " 2>&1 | tee -a " ++ RawLog @@ -123,8 +123,8 @@ check_log(RawLog) -> %% Show the log if it hasn't already been shown because verbose was on show_log(RawLog) -> ?CONSOLE("Showing log\n", []), - case rebar_config:get_global(verbose, "0") of - "0" -> + case rebar_config:is_verbose() of + true -> {ok, Contents} = file:read_file(RawLog), ?CONSOLE("~s", [Contents]); _ -> diff --git a/src/rebar_log.erl b/src/rebar_log.erl index 3be8d30..4fa7811 100644 --- a/src/rebar_log.erl +++ b/src/rebar_log.erl @@ -33,8 +33,8 @@ %% =================================================================== init() -> - case rebar_config:get_global(verbose, "0") of - "1" -> + case rebar_config:is_verbose() of + true -> set_level(debug); _ -> set_level(error) diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index e9bf1d3..3fc3606 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -63,11 +63,11 @@ install(Config, File) -> true -> %% Already exists -- check for force=1 global flag and only %% continue if it's set - case rebar_config:get_global(force, "0") of - "0" -> + case rebar_config:get_global(force, false) of + false -> ?ERROR("~s already exists. Installation failed.\n", [AppId]), ?FAIL; - "1" -> + true -> ?WARN("~s already exists, but forcibly overwriting.\n", [AppId]) end; false -> diff --git a/src/rebar_reltool.erl b/src/rebar_reltool.erl index 3b08be3..055bfb5 100644 --- a/src/rebar_reltool.erl +++ b/src/rebar_reltool.erl @@ -177,8 +177,8 @@ mk_target_dir(TargetDir) -> ok; {error, eexist} -> %% Output directory already exists; if force=1, wipe it out - case rebar_config:get_global(force, "0") of - "1" -> + case rebar_config:get_global(force, false) of + true -> rebar_file_utils:rm_rf(TargetDir), ok = file:make_dir(TargetDir); _ -> -- cgit v1.1 From 9a8015f2d78394e3652d2b7720442b77948412f6 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 31 Dec 2009 19:42:53 +0100 Subject: Added vi modeline/emacs local variables to file headers --- src/rebar.erl | 2 ++ src/rebar_app_utils.erl | 2 ++ src/rebar_config.erl | 2 ++ src/rebar_core.erl | 2 ++ src/rebar_ct.erl | 2 ++ src/rebar_deps.erl | 2 ++ src/rebar_erlc_compiler.erl | 2 ++ src/rebar_erlydtl_compiler.erl | 2 ++ src/rebar_escripter.erl | 2 ++ src/rebar_eunit.erl | 2 ++ src/rebar_file_utils.erl | 2 ++ src/rebar_lfe_compiler.erl | 2 ++ src/rebar_log.erl | 2 ++ src/rebar_otp_app.erl | 2 ++ src/rebar_port_compiler.erl | 2 ++ src/rebar_protobuffs_compiler.erl | 2 ++ src/rebar_rel_utils.erl | 2 ++ src/rebar_reltool.erl | 2 ++ src/rebar_subdirs.erl | 2 ++ src/rebar_utils.erl | 2 ++ 20 files changed, 40 insertions(+) diff --git a/src/rebar.erl b/src/rebar.erl index 5050326..c00191d 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index f879537..dbd085e 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_config.erl b/src/rebar_config.erl index 33bef58..4b2de1a 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_core.erl b/src/rebar_core.erl index a40419a..4250913 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 9cc05a1..7e6b745 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index 02a34d6..7e9c232 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index a2dc399..68b1d75 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_erlydtl_compiler.erl b/src/rebar_erlydtl_compiler.erl index dd0b7c7..862c5ed 100644 --- a/src/rebar_erlydtl_compiler.erl +++ b/src/rebar_erlydtl_compiler.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_escripter.erl b/src/rebar_escripter.erl index 6b07c27..19101b6 100644 --- a/src/rebar_escripter.erl +++ b/src/rebar_escripter.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index e3914fa..e32aa72 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 09f90e2..ae1f376 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_lfe_compiler.erl b/src/rebar_lfe_compiler.erl index 3776164..5447028 100644 --- a/src/rebar_lfe_compiler.erl +++ b/src/rebar_lfe_compiler.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_log.erl b/src/rebar_log.erl index 4fa7811..1f2dc41 100644 --- a/src/rebar_log.erl +++ b/src/rebar_log.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 3fc3606..a5d1046 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl index 6be6423..a602f01 100644 --- a/src/rebar_port_compiler.erl +++ b/src/rebar_port_compiler.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_protobuffs_compiler.erl b/src/rebar_protobuffs_compiler.erl index 540df9f..c754747 100644 --- a/src/rebar_protobuffs_compiler.erl +++ b/src/rebar_protobuffs_compiler.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl index 99d12f7..cf3e92e 100644 --- a/src/rebar_rel_utils.erl +++ b/src/rebar_rel_utils.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_reltool.erl b/src/rebar_reltool.erl index 055bfb5..8934403 100644 --- a/src/rebar_reltool.erl +++ b/src/rebar_reltool.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_subdirs.erl b/src/rebar_subdirs.erl index d4563a2..cb8f79b 100644 --- a/src/rebar_subdirs.erl +++ b/src/rebar_subdirs.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index d780419..05f9349 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -1,3 +1,5 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% rebar: Erlang Build Tools -- cgit v1.1 From 48048c82a6b56a7fc4f0ceeb2265623d6d7129dd Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 31 Dec 2009 20:31:22 +0100 Subject: Added HACKING, LICENSE and THANKS files --- HACKING | 11 ++++ LICENSE | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ THANKS | 7 +++ 3 files changed, 196 insertions(+) create mode 100644 HACKING create mode 100644 LICENSE create mode 100644 THANKS diff --git a/HACKING b/HACKING new file mode 100644 index 0000000..7b29add --- /dev/null +++ b/HACKING @@ -0,0 +1,11 @@ +Indenting +~~~~~~~~~ +To have consistent indenting we have vi modeline/emacs local variable +headers in rebar's source files. This works automatically with vi. +With Emacs you have to declare 'erlang-indent-level set to 4' +as a safe local variable value. If not configured Emacs will prompt +you to save this as part of custom-set-variables: + '(safe-local-variable-values (quote ((erlang-indent-level . 4)))) +You can also tell Emacs to ignore file variables: +(setq enable-local-variables nil + enable-local-eval nil) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e454a52 --- /dev/null +++ b/LICENSE @@ -0,0 +1,178 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/THANKS b/THANKS new file mode 100644 index 0000000..e0eb3b0 --- /dev/null +++ b/THANKS @@ -0,0 +1,7 @@ +The following people have contributed to rebar: + +Dave Smith +Jon Meredith +Tim Dysinger +Bryan Fink +Tuncer Ayaz -- cgit v1.1 From 0817dec7ca3a24955cc8f08fb359bf0f77ae1f4d Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 1 Jan 2010 00:08:00 +0100 Subject: Rolled back getopt to restore custom variables --- src/getopt.erl | 146 +++++++++++--------------------------------------- src/rebar_config.erl | 7 ++- src/rebar_core.erl | 41 +++++++++++--- src/rebar_ct.erl | 8 +-- src/rebar_log.erl | 4 +- src/rebar_otp_app.erl | 6 +-- src/rebar_reltool.erl | 4 +- 7 files changed, 82 insertions(+), 134 deletions(-) diff --git a/src/getopt.erl b/src/getopt.erl index edc8f3f..b335f0c 100644 --- a/src/getopt.erl +++ b/src/getopt.erl @@ -11,9 +11,6 @@ -module(getopt). -author('juanjo@comellas.org'). --export([parse/2, usage/2]). - - -define(TAB_LENGTH, 8). %% Indentation of the help messages in number of tabs. -define(INDENTATION, 3). @@ -47,6 +44,8 @@ Help :: string() | undefined }. +-export([parse/2, usage/2]). + -spec parse([option_spec()], string() | [string()]) -> {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data :: any()}}. %%-------------------------------------------------------------------- @@ -72,20 +71,12 @@ parse(OptSpecList, CmdLine) -> -spec parse([option_spec()], [option()], [string()], integer(), [string()]) -> {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data:: any()}}. %% Process long options. -parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | Name] = OptStr | Tail]) -> - {Option, Tail1} = - case split_embedded_arg(Name) of - {Name1, Arg} -> - %% Get option that has its argument within the same string - %% separated by an equal ('=') character. - {get_option_embedded_arg(OptSpecList, OptStr, ?OPT_LONG, Name1, Arg), Tail}; - _Name1 -> - get_option(OptSpecList, OptStr, ?OPT_LONG, Name, Tail) - end, +parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | LongName] = OptStr | Tail]) -> + {Option, Tail1} = get_option(OptSpecList, OptStr, LongName, ?OPT_LONG, Tail), parse(OptSpecList, [Option | OptAcc], ArgAcc, ArgPos, Tail1); %% Process short options. parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, ShortName] = OptStr | Tail]) -> - {Option, Tail1} = get_option(OptSpecList, OptStr, ?OPT_SHORT, ShortName, Tail), + {Option, Tail1} = get_option(OptSpecList, OptStr, ShortName, ?OPT_SHORT, Tail), parse(OptSpecList, [Option | OptAcc], ArgAcc, ArgPos, Tail1); %% Process multiple short options with no argument. parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | ShortNameList] = OptStr | Tail]) -> @@ -96,21 +87,12 @@ parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | ShortNameList] = OptStr | Tail end, OptAcc, ShortNameList), parse(OptSpecList, NewOptAcc, ArgAcc, ArgPos, Tail); %% Process non-option arguments. -parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [OptStr | Tail]) -> - case split_embedded_arg(OptStr) of - {Name, Arg} -> - %% Get option that has its argument within the same string - %% separated by an equal ('=') character. - parse(OptSpecList, [get_option_embedded_arg(OptSpecList, OptStr, ?OPT_LONG, Name, Arg) | OptAcc], - ArgAcc, ArgPos, Tail); - Arg -> - case find_non_option_arg(OptSpecList, ArgPos) of - {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) -> - parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], - ArgAcc, ArgPos + 1, Tail); - false -> - parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail) - end +parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) -> + case find_non_option_arg(OptSpecList, ArgPos) of + {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) -> + parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], ArgAcc, ArgPos + 1, Tail); + false -> + parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail) end; parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) -> %% Once we have completed gathering the options we add the ones that were @@ -118,75 +100,28 @@ parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) -> {ok, {lists:reverse(append_default_args(OptSpecList, OptAcc)), lists:reverse(ArgAcc)}}. --spec get_option([option_spec()], string(), integer(), string() | char(), [string()]) -> +-spec get_option([option_spec()], string(), string() | char(), integer(), [string()]) -> {option(), [string()]}. %% @doc Retrieve the specification corresponding to an option matching a string %% received on the command line. -get_option(OptSpecList, OptStr, FieldPos, OptName, Tail) -> +get_option(OptSpecList, OptStr, OptName, FieldPos, Tail) -> case lists:keysearch(OptName, FieldPos, OptSpecList) of {value, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec} -> case ArgSpec of undefined -> {Name, Tail}; _ -> - ArgSpecType = arg_spec_type(ArgSpec), case Tail of [Arg | Tail1] -> - case (ArgSpecType =:= boolean) andalso not is_boolean_arg(Arg) of - %% Special case for booleans: when the next string - %% is an option we assume the value is 'true'. - true -> - {{Name, true}, Tail}; - _ -> - {convert_option_arg(OptSpec, Arg), Tail1} - end; - [] -> - case ArgSpecType of - boolean -> - {{Name, true}, Tail}; - _ -> - throw({error, {missing_option_arg, Name}}) - end + {convert_option_arg(OptSpec, Arg), Tail1}; + [] -> + throw({error, {missing_option_arg, Name}}) end end; false -> throw({error, {invalid_option, OptStr}}) end. - --spec get_option_embedded_arg([option_spec()], string(), integer(), string(), - string()) -> option(). -%% @doc Retrieve the specification corresponding to an option matching a string -%% received on the command line that had its argument assigned within the -%% same string (e.g. "verbose=true"). -get_option_embedded_arg(OptSpecList, OptStr, FieldPos, OptName, Arg) -> - case lists:keysearch(OptName, FieldPos, OptSpecList) of - {value, {_Name, _Short, _Long, ArgSpec, _Help} = OptSpec} -> - case ArgSpec of - undefined -> - throw({error, {invalid_option_arg, OptStr}}); - _ -> - convert_option_arg(OptSpec, Arg) - end; - false -> - throw({error, {invalid_option, OptStr}}) - end. - - --spec split_embedded_arg(string()) -> {Name :: string(), Arg :: string()} | string(). -%% @doc Split an option string that may contain and option with its argument -%% separated by an equal ('=') character (e.g. "port=1000"). -split_embedded_arg(OptStr) -> - split_embedded_arg(OptStr, OptStr, []). - -split_embedded_arg(_OptStr, [$= | Tail], Acc) -> - {lists:reverse(Acc), Tail}; -split_embedded_arg(OptStr, [Char | Tail], Acc) -> - split_embedded_arg(OptStr, Tail, [Char | Acc]); -split_embedded_arg(OptStr, [], _Acc) -> - OptStr. - - -spec get_option_no_arg([option_spec()], string(), string() | char(), integer()) -> option(). %% @doc Retrieve the specification corresponding to an option that has no %% argument and matches a string received on the command line. @@ -194,20 +129,12 @@ get_option_no_arg(OptSpecList, OptStr, OptName, FieldPos) -> case lists:keysearch(OptName, FieldPos, OptSpecList) of {value, {Name, _Short, _Long, undefined, _Help}} -> Name; - {value, {Name, _Short, _Long, ArgSpec, _Help}} -> - case arg_spec_type(ArgSpec) of - %% Special case for booleans: if there is no argument we assume - %% the value is 'true'. - boolean -> - {Name, true}; - _ -> - throw({error, {missing_option_arg, Name}}) - end; + {value, {Name, _Short, _Long, _ArgSpec, _Help}} -> + throw({error, {missing_option_arg, Name}}); false -> throw({error, {invalid_option, OptStr}}) end. - -spec find_non_option_arg([option_spec()], integer()) -> {value, option_spec()} | false. %% @doc Find the option for the discrete argument in position specified in the %% Pos argument. @@ -238,30 +165,23 @@ append_default_args([], OptAcc) -> OptAcc. -%% -spec is_option(string()) -> boolean(). -%% is_option([Char | _Tail] = OptStr) -> -%% (Char =:= $-) orelse lists:member($=, OptStr). - - -spec convert_option_arg(option_spec(), string()) -> [option()]. %% @doc Convert the argument passed in the command line to the data type -%% indicated by the argument specification. +%% indicated byt the argument specification. convert_option_arg({Name, _Short, _Long, ArgSpec, _Help}, Arg) -> try - {Name, to_type(arg_spec_type(ArgSpec), Arg)} + Converted = case ArgSpec of + {Type, _DefaultArg} -> + to_type(Type, Arg); + Type when is_atom(Type) -> + to_type(Type, Arg) + end, + {Name, Converted} catch error:_ -> throw({error, {invalid_option_arg, {Name, Arg}}}) end. - --spec arg_spec_type(arg_spec()) -> arg_type() | undefined. -arg_spec_type({Type, _DefaultArg}) -> - Type; -arg_spec_type(Type) when is_atom(Type) -> - Type. - - -spec to_type(atom(), string()) -> arg_value(). to_type(binary, Arg) -> list_to_binary(Arg); @@ -272,19 +192,13 @@ to_type(integer, Arg) -> to_type(float, Arg) -> list_to_float(Arg); to_type(boolean, Arg) -> - is_boolean_arg(Arg); -to_type(_Type, Arg) -> - Arg. - - --spec is_boolean_arg(string()) -> boolean(). -is_boolean_arg(Arg) -> LowerArg = string:to_lower(Arg), (LowerArg =:= "true") orelse (LowerArg =:= "t") orelse (LowerArg =:= "yes") orelse (LowerArg =:= "y") orelse - (LowerArg =:= "on") orelse (LowerArg =:= "enabled") orelse - (LowerArg =:= "1"). - + (LowerArg =:= "on") orelse (LowerArg =:= "enabled"); +to_type(_Type, Arg) -> + Arg. + -spec usage([option_spec()], string()) -> ok. %%-------------------------------------------------------------------- diff --git a/src/rebar_config.erl b/src/rebar_config.erl index 4b2de1a..6ff31d5 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -83,7 +83,12 @@ get_global(Key, Default) -> end. is_verbose() -> - get_global(verbose, false). + case get_global(verbose, "0") of + "1" -> + true; + _ -> + false + end. %% =================================================================== 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), diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 7e6b745..2a03b11 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -73,8 +73,8 @@ run_test_if_present(TestDir, Config, File) -> run_test(TestDir, Config, _File) -> {Cmd, RawLog} = make_cmd(TestDir, Config), clear_log(RawLog), - case rebar_config:is_verbose() of - true -> + case rebar_config:get_global(verbose, "0") of + "0" -> Output = " >> " ++ RawLog ++ " 2>&1"; _ -> Output = " 2>&1 | tee -a " ++ RawLog @@ -125,8 +125,8 @@ check_log(RawLog) -> %% Show the log if it hasn't already been shown because verbose was on show_log(RawLog) -> ?CONSOLE("Showing log\n", []), - case rebar_config:is_verbose() of - true -> + case rebar_config:get_global(verbose, "0") of + "0" -> {ok, Contents} = file:read_file(RawLog), ?CONSOLE("~s", [Contents]); _ -> diff --git a/src/rebar_log.erl b/src/rebar_log.erl index 1f2dc41..4ec05c0 100644 --- a/src/rebar_log.erl +++ b/src/rebar_log.erl @@ -35,8 +35,8 @@ %% =================================================================== init() -> - case rebar_config:is_verbose() of - true -> + case rebar_config:get_global(verbose, "0") of + "1" -> set_level(debug); _ -> set_level(error) diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index a5d1046..6f4935f 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -65,11 +65,11 @@ install(Config, File) -> true -> %% Already exists -- check for force=1 global flag and only %% continue if it's set - case rebar_config:get_global(force, false) of - false -> + case rebar_config:get_global(force, "0") of + "0" -> ?ERROR("~s already exists. Installation failed.\n", [AppId]), ?FAIL; - true -> + "1" -> ?WARN("~s already exists, but forcibly overwriting.\n", [AppId]) end; false -> diff --git a/src/rebar_reltool.erl b/src/rebar_reltool.erl index 8934403..d16bc3f 100644 --- a/src/rebar_reltool.erl +++ b/src/rebar_reltool.erl @@ -179,8 +179,8 @@ mk_target_dir(TargetDir) -> ok; {error, eexist} -> %% Output directory already exists; if force=1, wipe it out - case rebar_config:get_global(force, false) of - true -> + case rebar_config:get_global(force, "0") of + "1" -> rebar_file_utils:rm_rf(TargetDir), ok = file:make_dir(TargetDir); _ -> -- cgit v1.1