diff options
| author | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-02-13 13:38:42 -0600 | 
|---|---|---|
| committer | Tristan Sloughter <tristan.sloughter@gmail.com> | 2015-02-13 13:38:42 -0600 | 
| commit | dcab8baca0d6e2baad6c42d758571e4da619894a (patch) | |
| tree | dc532991afca1208d1d395b16e9622e541326f5e /src | |
| parent | 4b162c5917fe3b377310b221f8e13327da1f96a8 (diff) | |
| parent | 36563c0ab99af2dd3656f737fbed39df13fc6f81 (diff) | |
Merge pull request #142 from rebar/wtf-provider
Initial WTF provider implementation
Diffstat (limited to 'src')
| -rw-r--r-- | src/rebar.app.src | 1 | ||||
| -rw-r--r-- | src/rebar3.erl | 4 | ||||
| -rw-r--r-- | src/rebar_prv_help.erl | 2 | ||||
| -rw-r--r-- | src/rebar_prv_wtf.erl | 100 | 
4 files changed, 105 insertions, 2 deletions
| diff --git a/src/rebar.app.src b/src/rebar.app.src index 1230436..7d5e119 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -43,6 +43,7 @@                       rebar_prv_release,                       rebar_prv_version,                       rebar_prv_common_test, +                     rebar_prv_wtf,                       rebar_prv_xref,                       rebar_prv_help]}          ]} diff --git a/src/rebar3.erl b/src/rebar3.erl index c062aa4..268be68 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -54,7 +54,8 @@ main(Args) ->              case code:which(Module) of                  non_existing ->                      ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []), -                    ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]); +                    ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]), +                    ?INFO("When submitting a bug report, please include the output of `rebar3 wtf \"your command\"`", []);                  _ ->                      ?ERROR(Module:format_error(Reason), [])              end, @@ -67,6 +68,7 @@ main(Args) ->              %% Dump this error to console              ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),              ?DEBUG("Uncaught error: ~p", [Error]), +            ?INFO("When submitting a bug report, please include the output of `rebar3 wtf \"your command\"`", []),              erlang:halt(1)      end. diff --git a/src/rebar_prv_help.erl b/src/rebar_prv_help.erl index 7d39959..9e22530 100644 --- a/src/rebar_prv_help.erl +++ b/src/rebar_prv_help.erl @@ -24,7 +24,7 @@ init(State) ->                                                                 {module, ?MODULE},                                                                 {bare, false},                                                                 {deps, ?DEPS}, -                                                               {example, "rebar help <task>"}, +                                                               {example, "rebar3 help <task>"},                                                                 {short_desc, "Display a list of tasks or help for a given task or subtask."},                                                                 {desc, "Display a list of tasks or help for a given task or subtask."},                                                                 {opts, [ diff --git a/src/rebar_prv_wtf.erl b/src/rebar_prv_wtf.erl new file mode 100644 index 0000000..f876760 --- /dev/null +++ b/src/rebar_prv_wtf.erl @@ -0,0 +1,100 @@ +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et + +-module(rebar_prv_wtf). + +-behaviour(provider). + +-export([init/1, +         do/1, +         format_error/1]). + +-include("rebar.hrl"). + +-define(PROVIDER, wtf). +-define(DEPS, []). +-define(ISSUES_URL, "https://github.com/rebar/rebar3/issues"). + +%% =================================================================== +%% Public API +%% =================================================================== + +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> +    State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, +                                                               {module, ?MODULE}, +                                                               {bare, false}, +                                                               {deps, ?DEPS}, +                                                               {example, "rebar3 wtf \"<task>\""}, +                                                               {short_desc, "Provide a crash report to be sent to the rebar3 issues page"}, +                                                               {desc, "Provide a crash report to be sent to the rebar3 issues page"}, +                                                               {opts, [ +                                                                      {task, undefined, undefined, string, "Task to print details for."} +                                                                      ]}])), +    {ok, State1}. + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. +do(State) -> +    %% Show command +    Task = rebar_state:command_args(State), +    Command = parse_task(Task), +    %% Show command version (if a plugin?) +    %% ... +    %% Show app versions (including rebar3) +    {ok, Vsn} = application:get_key(rebar, vsn), +    Vsns = application:which_applications(), +    %% Show OS and versions +    OS = erlang:system_info(system_architecture), +    %% Erlang version (ERTS) +    ERTS = erlang:system_info(system_version), +    %% ERTS root directory +    Root = code:root_dir(), +    Lib = code:lib_dir(), +    %% datetime +    UTC = calendar:universal_time(), +    %% +    ?CONSOLE( +        "Rebar3 wtf report~n" +        " version ~s~n" +        " generated at ~s~n" +        "=================~n" +        "Please submit this along with your issue at ~s " +        "(and feel free to edit out private information, if any)~n" +        "-----------------~n" +        "Task: ~ts~n" +        "Entered as:~n" +        "  ~ts~n" +        "-----------------~n" +        "Operating System: ~ts~n" +        "ERTS: ~ts" +        "Root Directory: ~ts~n" +        "Library directory: ~ts~n" +        "-----------------~n" +        "Loaded Applications:~n" +        "~p~n" +        "-----------------~n" +        "Escript path: ~ts~n" +        "Providers:~n" +        "  ~s", +        [Vsn, time_to_string(UTC), +         ?ISSUES_URL, Command, Task, +         OS, ERTS, Root, Lib, +         Vsns, +         rebar_state:escript_path(State), +         [providers:format(P)++" " +          || P <- lists:sort(rebar_state:providers(State))] +        ] +    ), +    {ok, State}. + +-spec format_error(any()) -> iolist(). +format_error(Reason) -> +    io_lib:format("~p", [Reason]). + +time_to_string({{Y,M,D},{H,Min,S}}) -> +    lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w+00:00", +                  [Y,M,D,H,Min,S])). + +parse_task(Str) -> +    hd(re:split(Str, " ")). + | 
