basho / rebar
Erlang Build Tools -- Please file bug and feature requests at http://issues.basho.com.
| commit 188: | e4b496704047 |
| parent 187: | 0baa8986ccfe |
| branch: | default |
Add option to show available commands
Implement new option -c/--commands to print available
commands and its variables.
Tuncer Ayaz /
tuncer
5 months ago
5 months ago
Changed (Δ1.4 KB):
raw changeset »
src/rebar_core.erl (73 lines added, 28 lines removed)
Up to file-list src/rebar_core.erl:
| … | … | @@ -85,32 +85,25 @@ parse_args(Args) -> |
85 |
85 |
%% Parse getopt options |
86 |
86 |
OptSpecList = option_spec_list(), |
87 |
87 |
case getopt:parse(OptSpecList, Args) of |
88 |
{ok, {_Options, []}} -> |
|
89 |
%% no command to run specified |
|
90 |
help(), |
|
91 |
halt(1); |
|
92 |
88 |
{ok, {Options, NonOptArgs}} -> |
93 |
case proplists:get_bool(help, Options) of |
|
94 |
true -> |
|
95 |
%% display help |
|
96 |
help(), |
|
97 |
halt(0); |
|
98 |
false -> |
|
99 |
%% Set global variables based on getopt options |
|
100 |
set_global_flag(Options, verbose), |
|
101 |
set_global_flag(Options, force), |
|
102 |
DefJobs = rebar_config:get_jobs(), |
|
103 |
case proplists:get_value(jobs, Options, DefJobs) of |
|
104 |
DefJobs -> |
|
105 |
ok; |
|
106 |
Jobs -> |
|
107 |
rebar_config:set_global(jobs, Jobs) |
|
108 |
end, |
|
89 |
%% Check options and maybe halt execution |
|
90 |
{ok, continue} = print_help_maybe_halt(Options, NonOptArgs), |
|
109 |
91 |
|
110 |
%% Filter all the flags (i.e. strings of form key=value) from the |
|
111 |
%% command line arguments. What's left will be the commands to run. |
|
112 |
filter_flags(NonOptArgs, []) |
|
113 |
end; |
|
92 |
%% Set global variables based on getopt options |
|
93 |
set_global_flag(Options, verbose), |
|
94 |
set_global_flag(Options, force), |
|
95 |
DefJobs = rebar_config:get_jobs(), |
|
96 |
case proplists:get_value(jobs, Options, DefJobs) of |
|
97 |
DefJobs -> |
|
98 |
ok; |
|
99 |
Jobs -> |
|
100 |
rebar_config:set_global(jobs, Jobs) |
|
101 |
end, |
|
102 |
||
103 |
%% Filter all the flags (i.e. strings of form key=value) from the |
|
104 |
%% command line arguments. What's left will be the commands to run. |
|
105 |
filter_flags(NonOptArgs, []); |
|
106 |
||
114 |
107 |
{error, {Reason, Data}} -> |
115 |
108 |
?ERROR("Error: ~s ~p~n~n", [Reason, Data]), |
116 |
109 |
help(), |
| … | … | @@ -130,6 +123,31 @@ set_global_flag(Options, Flag) -> |
130 |
123 |
rebar_config:set_global(Flag, Value). |
131 |
124 |
|
132 |
125 |
%% |
126 |
%% print help |
|
127 |
%% |
|
128 |
print_help_maybe_halt(Options, NonOptArgs) -> |
|
129 |
case proplists:get_bool(help, Options) of |
|
130 |
true -> |
|
131 |
help(), |
|
132 |
halt(0); |
|
133 |
false -> |
|
134 |
case proplists:get_bool(commands, Options) of |
|
135 |
true -> |
|
136 |
commands(), |
|
137 |
halt(0); |
|
138 |
false -> |
|
139 |
case NonOptArgs of |
|
140 |
[] -> |
|
141 |
io:format("No command to run specified!~n"), |
|
142 |
help(), |
|
143 |
halt(1); |
|
144 |
_ -> |
|
145 |
{ok, continue} |
|
146 |
end |
|
147 |
end |
|
148 |
end. |
|
149 |
||
150 |
%% |
|
133 |
151 |
%% print help/usage string |
134 |
152 |
%% |
135 |
153 |
help() -> |
| … | … | @@ -140,6 +158,32 @@ help() -> |
140 |
158 |
{"command", "Command to run (e.g. compile)"}]). |
141 |
159 |
|
142 |
160 |
%% |
161 |
%% print known commands |
|
162 |
%% |
|
163 |
commands() -> |
|
164 |
io:format(<< |
|
165 |
"analyze Analyze with Dialyzer~n" |
|
166 |
"build_plt Build Dialyzer PLT~n" |
|
167 |
"check_plt Check Dialyzer PLT~n" |
|
168 |
"~n" |
|
169 |
"clean Clean~n" |
|
170 |
"compile Compile sources~n" |
|
171 |
"~n" |
|
172 |
"create template= [var=foo,...] Create skel based on template and vars~n" |
|
173 |
"create-app Create simple app skel~n" |
|
174 |
"create-node Create simple node skel~n" |
|
175 |
"~n" |
|
176 |
"generate [dump_spec=0/1] Build release with reltool~n" |
|
177 |
"install [target=] Install build into target~n" |
|
178 |
"~n" |
|
179 |
"eunit [suite=foo] Run eunit [test/foo_tests.erl] tests~n" |
|
180 |
"~n" |
|
181 |
"int_test [suite=] [case=] Run ct suites in ./int_test~n" |
|
182 |
"perf_test [suite=] [case=] Run ct suites in ./perf_test~n" |
|
183 |
"test [suite=] [case=] Run ct suites in ./test~n" |
|
184 |
>>). |
|
185 |
||
186 |
%% |
|
143 |
187 |
%% options accepted via getopt |
144 |
188 |
%% |
145 |
189 |
option_spec_list() -> |
| … | … | @@ -149,10 +193,11 @@ option_spec_list() -> |
149 |
193 |
[Jobs]), |
150 |
194 |
[ |
151 |
195 |
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} |
152 |
{help, $h, "help", undefined, "Show the program options"}, |
|
153 |
{verbose, $v, "verbose", undefined, "Be verbose about what gets done"}, |
|
154 |
{force, $f, "force", undefined, "Force"}, |
|
155 |
{jobs, $j, "jobs", integer, JobsHelp} |
|
196 |
{help, $h, "help", undefined, "Show the program options"}, |
|
197 |
{commands, $c, "commands", undefined, "Show available commands"}, |
|
198 |
{verbose, $v, "verbose", undefined, "Be verbose about what gets done"}, |
|
199 |
{force, $f, "force", undefined, "Force"}, |
|
200 |
{jobs, $j, "jobs", integer, JobsHelp} |
|
156 |
201 |
]. |
157 |
202 |
|
158 |
203 |
%% |
