Просмотр исходного кода

feat(shell): add emqx version to prompt.

zhongwencool 4 лет назад
Родитель
Сommit
3efa583830

+ 1 - 0
apps/emqx_machine/src/emqx_machine_app.erl

@@ -24,6 +24,7 @@
 
 
 start(_Type, _Args) ->
 start(_Type, _Args) ->
     ok = emqx_machine:start(),
     ok = emqx_machine:start(),
+    emqx_restricted_shell:set_prompt_func(),
     emqx_machine_sup:start_link().
     emqx_machine_sup:start_link().
 
 
 stop(_State) ->
 stop(_State) ->

+ 12 - 0
apps/emqx_machine/src/emqx_restricted_shell.erl

@@ -17,6 +17,7 @@
 -module(emqx_restricted_shell).
 -module(emqx_restricted_shell).
 
 
 -export([local_allowed/3, non_local_allowed/3]).
 -export([local_allowed/3, non_local_allowed/3]).
+-export([set_prompt_func/0, prompt_func/1]).
 -export([lock/0, unlock/0, is_locked/0]).
 -export([lock/0, unlock/0, is_locked/0]).
 
 
 -include_lib("emqx/include/logger.hrl").
 -include_lib("emqx/include/logger.hrl").
@@ -38,6 +39,17 @@ is_locked() ->
 lock() -> application:set_env(?APP, ?IS_LOCKED, true).
 lock() -> application:set_env(?APP, ?IS_LOCKED, true).
 unlock() -> application:set_env(?APP, ?IS_LOCKED, false).
 unlock() -> application:set_env(?APP, ?IS_LOCKED, false).
 
 
+set_prompt_func() ->
+    shell:prompt_func({?MODULE, prompt_func}).
+
+prompt_func(PropList) ->
+    Line = proplists:get_value(history, PropList, 1),
+    Version = emqx_release:version(),
+    case is_alive() of
+        true  -> io_lib:format(<<"~ts(~s)~w> ">>, [Version, node(), Line]);
+        false -> io_lib:format(<<"~ts ~w> ">>, [Version, Line])
+    end.
+
 local_allowed(MF, Args, State) ->
 local_allowed(MF, Args, State) ->
     IsAllowed = is_allowed(MF, ?LOCAL_NOT_ALLOWED),
     IsAllowed = is_allowed(MF, ?LOCAL_NOT_ALLOWED),
     log(IsAllowed, MF, Args),
     log(IsAllowed, MF, Args),

+ 0 - 1
apps/emqx_machine/src/user_default.erl

@@ -20,7 +20,6 @@
 -include_lib("emqx/include/emqx_mqtt.hrl").
 -include_lib("emqx/include/emqx_mqtt.hrl").
 -include_lib("emqx_conf/include/emqx_conf.hrl").
 -include_lib("emqx_conf/include/emqx_conf.hrl").
 -include_lib("emqx_dashboard/include/emqx_dashboard.hrl").
 -include_lib("emqx_dashboard/include/emqx_dashboard.hrl").
--include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl").
 
 
 %% API
 %% API
 -export([lock/0, unlock/0]).
 -export([lock/0, unlock/0]).