Merge pull request #332 from emqtt/dev-feng

allow to override a cli command
This commit is contained in:
Feng Lee 2015-10-10 23:09:33 +08:00
commit d151cc2099
2 changed files with 9 additions and 1 deletions

View File

@ -43,6 +43,8 @@
clients/1, sessions/1, plugins/1, listeners/1,
vm/1, mnesia/1, trace/1]).
-export([node_name/1]).
-define(PROC_INFOKEYS, [status,
memory,
message_queue_len,

View File

@ -110,7 +110,13 @@ handle_call(_Request, _From, State) ->
{reply, ok, State}.
handle_cast({register_cmd, Cmd, MF, Opts}, State = #state{seq = Seq}) ->
ets:insert(?CMD_TAB, {{Seq, Cmd}, MF, Opts}),
case ets:match(?CMD_TAB, {{'$1', Cmd}, '_', '_'}) of
[] ->
ets:insert(?CMD_TAB, {{Seq, Cmd}, MF, Opts});
[[OriginSeq] | _] ->
lager:warning("CLI: ~s is overidden by ~p", [Cmd, MF]),
ets:insert(?CMD_TAB, {{OriginSeq, Cmd}, MF, Opts})
end,
noreply(next_seq(State));
handle_cast({unregister_cmd, Cmd}, State) ->