feat(shell): add emqx version to prompt.

This commit is contained in:
zhongwencool 2022-01-30 14:57:14 +08:00
parent 6a701e098f
commit 3efa583830
3 changed files with 13 additions and 1 deletions

View File

@ -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) ->

View File

@ -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),

View File

@ -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]).