Update Cli command
This commit is contained in:
parent
2d6104fbd9
commit
06d291e354
|
@ -95,7 +95,7 @@ register_cmd() ->
|
||||||
listeners().
|
listeners().
|
||||||
|
|
||||||
node_status() ->
|
node_status() ->
|
||||||
Cmd = ["status"],
|
Cmd = ["status", "info"],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, _, _) ->
|
fun (_, _, _) ->
|
||||||
{Status, Vsn} = case lists:keysearch(?APP, 1, application:which_applications()) of
|
{Status, Vsn} = case lists:keysearch(?APP, 1, application:which_applications()) of
|
||||||
|
@ -399,14 +399,26 @@ subscriptions_subscribe() ->
|
||||||
{'qos', [{typecast, fun(QoS) -> list_to_integer(QoS) end}]}],
|
{'qos', [{typecast, fun(QoS) -> list_to_integer(QoS) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, ClientId}, {_, Topic}, {_, QoS}], _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case emqttd:subscribe(Topic, ClientId, [{qos, QoS}]) of
|
Topic = get_value('topic', Params),
|
||||||
ok ->
|
ClientId = get_value('client_id', Params),
|
||||||
io_lib:format("Client_id: ~p subscribe topic: ~p qos: ~p successfully~n", [ClientId, Topic, QoS]);
|
QoS = get_value('qos', Params),
|
||||||
{error, already_existed} ->
|
Text = case {Topic, ClientId, QoS} of
|
||||||
io_lib:format("Error: client_id: ~p subscribe topic: ~p already existed~n", [ClientId, Topic]);
|
{undefined, _, _} ->
|
||||||
{error, Reason} ->
|
io_lib:format("Invalid topic is undefined~n", []);
|
||||||
io_lib:format("Error: ~p~n", [Reason])
|
{_, undefined, _} ->
|
||||||
|
io_lib:format("Invalid client_id is undefined~n", []);
|
||||||
|
{_, _, undefined} ->
|
||||||
|
io_lib:format("Invalid qos is undefined~n", []);
|
||||||
|
{_, _, _} ->
|
||||||
|
case emqttd:subscribe(Topic, ClientId, [{qos, QoS}]) of
|
||||||
|
ok ->
|
||||||
|
io_lib:format("Client_id: ~p subscribe topic: ~p qos: ~p successfully~n", [ClientId, Topic, QoS]);
|
||||||
|
{error, already_existed} ->
|
||||||
|
io_lib:format("Error: client_id: ~p subscribe topic: ~p already existed~n", [ClientId, Topic]);
|
||||||
|
{error, Reason} ->
|
||||||
|
io_lib:format("Error: ~p~n", [Reason])
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -430,9 +442,19 @@ subscriptions_unsubscribe() ->
|
||||||
{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, ClientId}, {_, Topic}], _) ->
|
fun (_, Params, _) ->
|
||||||
emqttd:unsubscribe(Topic, ClientId),
|
Topic = get_value('topic', Params),
|
||||||
Text = io_lib:format("Client_id: ~p unsubscribe topic: ~p successfully~n", [ClientId, Topic]),
|
ClientId = get_value('client_id', Params),
|
||||||
|
QoS = get_value('qos', Params),
|
||||||
|
Text = case {Topic, ClientId, QoS} of
|
||||||
|
{undefined, _} ->
|
||||||
|
io_lib:format("Invalid topic is undefined~n", []);
|
||||||
|
{_, undefined} ->
|
||||||
|
io_lib:format("Invalid client_id is undefined~n", []);
|
||||||
|
{_, _} ->
|
||||||
|
emqttd:unsubscribe(Topic, ClientId),
|
||||||
|
io_lib:format("Client_id: ~p unsubscribe topic: ~p successfully~n", [ClientId, Topic])
|
||||||
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
clique:register_command(Cmd, KeySpecs, FlagSpecs, Callback).
|
||||||
|
@ -508,12 +530,10 @@ bridges_start() ->
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, Params, _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
||||||
{undefined, undefined} ->
|
|
||||||
io_lib:format("Invalid snode and topic error~n", []);
|
|
||||||
{undefined, _} ->
|
{undefined, _} ->
|
||||||
io_lib:format("Invalid snode error~n", []);
|
io_lib:format("Invalid snode is undefined~n", []);
|
||||||
{_, undefined} ->
|
{_, undefined} ->
|
||||||
io_lib:format("Invalid topic error~n", []);
|
io_lib:format("Invalid topic is undefined~n", []);
|
||||||
{SNode, Topic} ->
|
{SNode, Topic} ->
|
||||||
Opts = Params -- [{'snode', SNode}, {'topic', Topic}],
|
Opts = Params -- [{'snode', SNode}, {'topic', Topic}],
|
||||||
case emqttd_bridge_sup_sup:start_bridge(SNode, Topic, Opts) of
|
case emqttd_bridge_sup_sup:start_bridge(SNode, Topic, Opts) of
|
||||||
|
@ -533,10 +553,17 @@ bridges_stop() ->
|
||||||
{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
{'topic', [{typecast, fun(Topic) -> list_to_binary(Topic) end}]}],
|
||||||
FlagSpecs = [],
|
FlagSpecs = [],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, [{_, SNode},{_, Topic}], _) ->
|
fun (_, Params, _) ->
|
||||||
Text = case emqttd_bridge_sup_sup:stop_bridge(SNode, Topic) of
|
Text = case {get_value('snode', Params), get_value('topic', Params)} of
|
||||||
ok -> io_lib:format("bridge is stopped.~n", []);
|
{undefined, _} ->
|
||||||
{error, Error} -> io_lib:format("error: ~p~n", [Error])
|
io_lib:format("Invalid snode is undefined~n", []);
|
||||||
|
{_, undefined} ->
|
||||||
|
io_lib:format("Invalid topic is undefined~n", []);
|
||||||
|
{SNode, Topic} ->
|
||||||
|
case emqttd_bridge_sup_sup:stop_bridge(SNode, Topic) of
|
||||||
|
ok -> io_lib:format("bridge is stopped.~n", []);
|
||||||
|
{error, Error} -> io_lib:format("error: ~p~n", [Error])
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
[clique_status:text(Text)]
|
[clique_status:text(Text)]
|
||||||
end,
|
end,
|
||||||
|
@ -718,7 +745,7 @@ trace_off(Who, Name) ->
|
||||||
%% @doc Listeners Command
|
%% @doc Listeners Command
|
||||||
|
|
||||||
listeners() ->
|
listeners() ->
|
||||||
Cmd = ["listeners"],
|
Cmd = ["listeners", "info"],
|
||||||
Callback =
|
Callback =
|
||||||
fun (_, _, _) ->
|
fun (_, _, _) ->
|
||||||
Table =
|
Table =
|
||||||
|
@ -807,10 +834,10 @@ trace_usage() ->
|
||||||
" trace off type=client|topic client_id=<ClientId> topic=<Topic> Stop tracing\n"].
|
" trace off type=client|topic client_id=<ClientId> topic=<Topic> Stop tracing\n"].
|
||||||
|
|
||||||
status_usage() ->
|
status_usage() ->
|
||||||
["\n status Show broker status\n"].
|
["\n status info Show broker status\n"].
|
||||||
|
|
||||||
listeners_usage() ->
|
listeners_usage() ->
|
||||||
["\n listeners List listeners\n"].
|
["\n listeners info List listeners\n"].
|
||||||
|
|
||||||
mnesia_usage() ->
|
mnesia_usage() ->
|
||||||
["\n mnesia info Mnesia system info\n"].
|
["\n mnesia info Mnesia system info\n"].
|
||||||
|
|
Loading…
Reference in New Issue