fix subscriptions cli

This commit is contained in:
Feng 2015-12-16 11:04:51 +08:00
parent 7cd5367f3b
commit e37b00a9e4
1 changed files with 12 additions and 4 deletions

View File

@ -241,19 +241,26 @@ subscriptions(["list"]) ->
subscriptions(["show", ClientId]) -> subscriptions(["show", ClientId]) ->
if_subscription(fun() -> if_subscription(fun() ->
case emqttd_pubsub:lookup(subscription, ClientId) of case emqttd_pubsub:lookup(subscription, bin(ClientId)) of
[] -> ?PRINT_MSG("Not Found.~n"); [] -> ?PRINT_MSG("Not Found.~n");
Records -> print(subscription, ClientId, Records) Records -> print(subscription, ClientId, Records)
end end
end); end);
subscriptions(["add", ClientId, Topic, QoS]) -> subscriptions(["add", ClientId, Topic, QoS]) ->
Create = fun(IntQos) -> emqttd_pubsub:create(subscription, {ClientId, Topic, IntQos}) end, Create = fun(IntQos) ->
Subscription = {bin(ClientId), bin(Topic), IntQos},
case emqttd_pubsub:create(subscription, Subscription) of
ok -> ?PRINT_MSG("ok~n");
{error, Error} -> ?PRINT("Error: ~p~n", [Error])
end
end,
if_subscription(fun() -> if_valid_qos(QoS, Create) end); if_subscription(fun() -> if_valid_qos(QoS, Create) end);
subscriptions(["del", ClientId, Topic]) -> subscriptions(["del", ClientId, Topic]) ->
if_subscription(fun() -> if_subscription(fun() ->
emqttd_pubsub:delete(subscription, {ClientId, Topic}) Ok = emqttd_pubsub:delete(subscription, {bin(ClientId), bin(Topic)}),
?PRINT("~p~n", [Ok])
end); end);
subscriptions(_) -> subscriptions(_) ->
@ -279,7 +286,8 @@ if_could_print(Tab, Fun) ->
if_valid_qos(QoS, Fun) -> if_valid_qos(QoS, Fun) ->
try list_to_integer(QoS) of try list_to_integer(QoS) of
Int when ?IS_QOS(Int) -> Fun(Int) Int when ?IS_QOS(Int) -> Fun(Int);
_ -> ?PRINT_MSG("QoS should be 0, 1, 2~n")
catch _:_ -> catch _:_ ->
?PRINT_MSG("QoS should be 0, 1, 2~n") ?PRINT_MSG("QoS should be 0, 1, 2~n")
end. end.