mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Add option to show available commands
Implement new option -c/--commands to print available commands and its variables.
This commit is contained in:
parent
218051618f
commit
ebfb1dc40d
1 changed files with 73 additions and 28 deletions
|
@ -85,17 +85,10 @@ parse_args(Args) ->
|
||||||
%% Parse getopt options
|
%% Parse getopt options
|
||||||
OptSpecList = option_spec_list(),
|
OptSpecList = option_spec_list(),
|
||||||
case getopt:parse(OptSpecList, Args) of
|
case getopt:parse(OptSpecList, Args) of
|
||||||
{ok, {_Options, []}} ->
|
|
||||||
%% no command to run specified
|
|
||||||
help(),
|
|
||||||
halt(1);
|
|
||||||
{ok, {Options, NonOptArgs}} ->
|
{ok, {Options, NonOptArgs}} ->
|
||||||
case proplists:get_bool(help, Options) of
|
%% Check options and maybe halt execution
|
||||||
true ->
|
{ok, continue} = print_help_maybe_halt(Options, NonOptArgs),
|
||||||
%% display help
|
|
||||||
help(),
|
|
||||||
halt(0);
|
|
||||||
false ->
|
|
||||||
%% Set global variables based on getopt options
|
%% Set global variables based on getopt options
|
||||||
set_global_flag(Options, verbose),
|
set_global_flag(Options, verbose),
|
||||||
set_global_flag(Options, force),
|
set_global_flag(Options, force),
|
||||||
|
@ -109,8 +102,8 @@ parse_args(Args) ->
|
||||||
|
|
||||||
%% Filter all the flags (i.e. strings of form key=value) from the
|
%% Filter all the flags (i.e. strings of form key=value) from the
|
||||||
%% command line arguments. What's left will be the commands to run.
|
%% command line arguments. What's left will be the commands to run.
|
||||||
filter_flags(NonOptArgs, [])
|
filter_flags(NonOptArgs, []);
|
||||||
end;
|
|
||||||
{error, {Reason, Data}} ->
|
{error, {Reason, Data}} ->
|
||||||
?ERROR("Error: ~s ~p~n~n", [Reason, Data]),
|
?ERROR("Error: ~s ~p~n~n", [Reason, Data]),
|
||||||
help(),
|
help(),
|
||||||
|
@ -129,6 +122,31 @@ set_global_flag(Options, Flag) ->
|
||||||
end,
|
end,
|
||||||
rebar_config:set_global(Flag, Value).
|
rebar_config:set_global(Flag, Value).
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% print help
|
||||||
|
%%
|
||||||
|
print_help_maybe_halt(Options, NonOptArgs) ->
|
||||||
|
case proplists:get_bool(help, Options) of
|
||||||
|
true ->
|
||||||
|
help(),
|
||||||
|
halt(0);
|
||||||
|
false ->
|
||||||
|
case proplists:get_bool(commands, Options) of
|
||||||
|
true ->
|
||||||
|
commands(),
|
||||||
|
halt(0);
|
||||||
|
false ->
|
||||||
|
case NonOptArgs of
|
||||||
|
[] ->
|
||||||
|
io:format("No command to run specified!~n"),
|
||||||
|
help(),
|
||||||
|
halt(1);
|
||||||
|
_ ->
|
||||||
|
{ok, continue}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% print help/usage string
|
%% print help/usage string
|
||||||
%%
|
%%
|
||||||
|
@ -139,6 +157,32 @@ help() ->
|
||||||
[{"var=value", "rebar global variables (e.g. force=1)"},
|
[{"var=value", "rebar global variables (e.g. force=1)"},
|
||||||
{"command", "Command to run (e.g. compile)"}]).
|
{"command", "Command to run (e.g. compile)"}]).
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% print known commands
|
||||||
|
%%
|
||||||
|
commands() ->
|
||||||
|
io:format(<<
|
||||||
|
"analyze Analyze with Dialyzer~n"
|
||||||
|
"build_plt Build Dialyzer PLT~n"
|
||||||
|
"check_plt Check Dialyzer PLT~n"
|
||||||
|
"~n"
|
||||||
|
"clean Clean~n"
|
||||||
|
"compile Compile sources~n"
|
||||||
|
"~n"
|
||||||
|
"create template= [var=foo,...] Create skel based on template and vars~n"
|
||||||
|
"create-app Create simple app skel~n"
|
||||||
|
"create-node Create simple node skel~n"
|
||||||
|
"~n"
|
||||||
|
"generate [dump_spec=0/1] Build release with reltool~n"
|
||||||
|
"install [target=] Install build into target~n"
|
||||||
|
"~n"
|
||||||
|
"eunit [suite=foo] Run eunit [test/foo_tests.erl] tests~n"
|
||||||
|
"~n"
|
||||||
|
"int_test [suite=] [case=] Run ct suites in ./int_test~n"
|
||||||
|
"perf_test [suite=] [case=] Run ct suites in ./perf_test~n"
|
||||||
|
"test [suite=] [case=] Run ct suites in ./test~n"
|
||||||
|
>>).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% options accepted via getopt
|
%% options accepted via getopt
|
||||||
%%
|
%%
|
||||||
|
@ -150,6 +194,7 @@ option_spec_list() ->
|
||||||
[
|
[
|
||||||
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
|
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
|
||||||
{help, $h, "help", undefined, "Show the program options"},
|
{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"},
|
{verbose, $v, "verbose", undefined, "Be verbose about what gets done"},
|
||||||
{force, $f, "force", undefined, "Force"},
|
{force, $f, "force", undefined, "Force"},
|
||||||
{jobs, $j, "jobs", integer, JobsHelp}
|
{jobs, $j, "jobs", integer, JobsHelp}
|
||||||
|
|
Loading…
Reference in a new issue