Bladeren bron

Handle force flags in leading position

The checking of flags and the parsing of arguments is separated up.
pull/930/head
Fred Hebert 9 jaren geleden
bovenliggende
commit
bf347caa55
2 gewijzigde bestanden met toevoegingen van 43 en 2 verwijderingen
  1. +5
    -1
      src/rebar_prv_new.erl
  2. +38
    -1
      test/rebar_new_SUITE.erl

+ 5
- 1
src/rebar_prv_new.erl Bestand weergeven

@ -32,7 +32,7 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) -> do(State) ->
case rebar_state:command_args(State) of
case strip_flags(rebar_state:command_args(State)) of
["help"] -> ["help"] ->
?CONSOLE("Call `rebar3 new help <template>` for a detailed description~n", []), ?CONSOLE("Call `rebar3 new help <template>` for a detailed description~n", []),
show_short_templates(rebar_templater:list_templates(State)), show_short_templates(rebar_templater:list_templates(State)),
@ -72,6 +72,10 @@ info() ->
"Valid command line options:~n" "Valid command line options:~n"
" <template> [var=foo,...]~n", []). " <template> [var=foo,...]~n", []).
strip_flags([]) -> [];
strip_flags(["-"++_|Opts]) -> strip_flags(Opts);
strip_flags([Opt | Opts]) -> [Opt | strip_flags(Opts)].
is_forced(State) -> is_forced(State) ->
{Args, _} = rebar_state:command_parsed_args(State), {Args, _} = rebar_state:command_parsed_args(State),
case proplists:get_value(force, Args) of case proplists:get_value(force, Args) of

+ 38
- 1
test/rebar_new_SUITE.erl Bestand weergeven

@ -6,7 +6,8 @@
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
all() -> [app_git_user, app_hg_user, app_with_fallbacks].
all() -> [app_git_user, app_hg_user, app_with_fallbacks,
app_with_flags1, app_with_flags2].
init_per_testcase(Case, Config0) -> init_per_testcase(Case, Config0) ->
@ -95,6 +96,42 @@ app_hg_user(Config) ->
{filename:join(["src", Name++"_app.erl"]), [Name]} {filename:join(["src", Name++"_app.erl"]), [Name]}
]). ]).
app_with_flags1(Config) ->
Name = ?config(name, Config),
rebar_test_utils:run_and_check(
Config, [],
["new", "test_app", "-f", Name],
{ok, []}
),
validate_files(
Config, Name,
[{"LICENSE", []},
{"README.md", []},
{".gitignore", []},
{"rebar.config", []},
{filename:join(["src", Name++".app.src"]), [Name]},
{filename:join(["src", Name++"_sup.erl"]), [Name]},
{filename:join(["src", Name++"_app.erl"]), [Name]}
]).
app_with_flags2(Config) ->
Name = ?config(name, Config),
rebar_test_utils:run_and_check(
Config, [],
["new", "-f", "test_app", Name],
{ok, []}
),
validate_files(
Config, Name,
[{"LICENSE", []},
{"README.md", []},
{".gitignore", []},
{"rebar.config", []},
{filename:join(["src", Name++".app.src"]), [Name]},
{filename:join(["src", Name++"_sup.erl"]), [Name]},
{filename:join(["src", Name++"_app.erl"]), [Name]}
]).
validate_files(_Config, Name, Checks) -> validate_files(_Config, Name, Checks) ->
[begin [begin
Path = filename:join([Name, File]), Path = filename:join([Name, File]),

Laden…
Annuleren
Opslaan