Browse Source

Add a state display provider

The provider is used for debugging to help displaying current rebar's state.

Usage:
  rebar3 state
pull/984/head
Serge Aleynikov 9 years ago
parent
commit
cf03345486
6 changed files with 62 additions and 4 deletions
  1. +1
    -0
      README.md
  2. +1
    -0
      src/rebar.app.src
  3. +5
    -4
      src/rebar3.erl
  4. +1
    -0
      src/rebar_hooks.erl
  5. +44
    -0
      src/rebar_prv_state.erl
  6. +10
    -0
      src/rebar_state.erl

+ 1
- 0
README.md View File

@ -42,6 +42,7 @@ locations ([hex.pm](http://hex.pm), git, hg, and so on).
| relup | Creates relup from 2 releases |
| report | Report on environment and versions for bug reports |
| shell | Run shell with project apps in path |
| state | Display configuration state |
| tar | Package release into tarball |
| tree | Print dependency tree |
| unlock | Unlock dependencies |

+ 1
- 0
src/rebar.app.src View File

@ -66,6 +66,7 @@
rebar_prv_relup,
rebar_prv_report,
rebar_prv_shell,
rebar_prv_state,
rebar_prv_tar,
rebar_prv_unlock,
rebar_prv_update,

+ 5
- 4
src/rebar3.erl View File

@ -247,10 +247,11 @@ set_global_flag(State, Options, Flag) ->
%%
global_option_spec_list() ->
[
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
{help, $h, "help", undefined, "Print this help."},
{version, $v, "version", undefined, "Show version information."},
{task, undefined, undefined, string, "Task to run."}
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
{help, $h, "help", undefined, "Print this help."},
{version, $v, "version", undefined, "Show version information."},
{task, undefined, undefined, string, "Task to run."},
{state, undefined, "state", undefined, "Display configuration state"}
].
handle_error(rebar_abort) ->

+ 1
- 0
src/rebar_hooks.erl View File

@ -81,6 +81,7 @@ run_hooks(Dir, post, Command, Opts, State) ->
run_hooks(Dir, Type, Command, Opts, State) ->
case rebar_opts:get(Opts, Type, []) of
[] ->
?DEBUG("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),
ok;
Hooks ->
Env = create_env(State, Opts),

+ 44
- 0
src/rebar_prv_state.erl View File

@ -0,0 +1,44 @@
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 et
-module(rebar_prv_state).
-behaviour(provider).
-export([init/1,
do/1,
format_error/1]).
-include("rebar.hrl").
-define(PROVIDER, state).
-define(DEPS, []).
%% ===================================================================
%% Public API
%% ===================================================================
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
Provider = providers:create(
[{name, ?PROVIDER},
{module, ?MODULE},
{bare, true},
{deps, ?DEPS},
{example, "rebar3 state"},
{short_desc, "Print current configuration state"},
{desc, "Display rebar configuration for debugging purpose"},
{opts, []}]),
State1 = rebar_state:add_provider(State, Provider),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
L = rebar_state:to_list(State),
io:put_chars("State:\n"),
[io:format(" ~w: ~p\n", [K, V]) || {K,V} <- L],
{ok, State}.
-spec format_error(any()) -> iolist().
format_error(Reason) ->
io_lib:format("~p", [Reason]).

+ 10
- 0
src/rebar_state.erl View File

@ -36,6 +36,7 @@
deps_names/1,
to_list/1,
resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2]).
@ -406,6 +407,15 @@ create_logic_providers(ProviderModules, State0) ->
throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."})
end.
to_list(#state_t{opts=O, code_paths=CP, default=D} = State) ->
O1 = dict:to_list(O),
CP1 = dict:to_list(CP),
D1 = dict:to_list(D),
State1 = State#state_t{opts=O1, code_paths=CP1, default=D1},
Fields = record_info(fields, state_t),
Values = tl(tuple_to_list(State1)),
lists:zip(Fields, Values).
%% ===================================================================
%% Internal functions
%% ===================================================================

Loading…
Cancel
Save