chore: fix elvis warnings

This commit is contained in:
JianBo He 2021-11-10 18:28:53 +08:00 committed by Zaiming Shi
parent 9e333ac8b3
commit a113b9b65d
1 changed files with 53 additions and 35 deletions

View File

@ -79,10 +79,12 @@ broker([]) ->
emqx_ctl:print("~-10s: ~p~n", [uptime, emqx_sys:uptime()]); emqx_ctl:print("~-10s: ~p~n", [uptime, emqx_sys:uptime()]);
broker(["stats"]) -> broker(["stats"]) ->
[emqx_ctl:print("~-30s: ~w~n", [Stat, Val]) || {Stat, Val} <- lists:sort(emqx_stats:getstats())]; [emqx_ctl:print("~-30s: ~w~n", [Stat, Val])
|| {Stat, Val} <- lists:sort(emqx_stats:getstats())];
broker(["metrics"]) -> broker(["metrics"]) ->
[emqx_ctl:print("~-30s: ~w~n", [Metric, Val]) || {Metric, Val} <- lists:sort(emqx_metrics:all())]; [emqx_ctl:print("~-30s: ~w~n", [Metric, Val])
|| {Metric, Val} <- lists:sort(emqx_metrics:all())];
broker(_) -> broker(_) ->
emqx_ctl:usage([{"broker", "Show broker version, uptime and description"}, emqx_ctl:usage([{"broker", "Show broker version, uptime and description"},
@ -207,10 +209,11 @@ subscriptions(["del", ClientId, Topic]) ->
end; end;
subscriptions(_) -> subscriptions(_) ->
emqx_ctl:usage([{"subscriptions list", "List all subscriptions"}, emqx_ctl:usage(
{"subscriptions show <ClientId>", "Show subscriptions of a client"}, [{"subscriptions list", "List all subscriptions"},
{"subscriptions add <ClientId> <Topic> <QoS>", "Add a static subscription manually"}, {"subscriptions show <ClientId>", "Show subscriptions of a client"},
{"subscriptions del <ClientId> <Topic>", "Delete a static subscription manually"}]). {"subscriptions add <ClientId> <Topic> <QoS>", "Add a static subscription manually"},
{"subscriptions del <ClientId> <Topic>", "Delete a static subscription manually"}]).
if_valid_qos(QoS, Fun) -> if_valid_qos(QoS, Fun) ->
try list_to_integer(QoS) of try list_to_integer(QoS) of
@ -279,14 +282,17 @@ vm(["memory"]) ->
[emqx_ctl:print("memory/~-17s: ~w~n", [Cat, Val]) || {Cat, Val} <- erlang:memory()]; [emqx_ctl:print("memory/~-17s: ~w~n", [Cat, Val]) || {Cat, Val} <- erlang:memory()];
vm(["process"]) -> vm(["process"]) ->
[emqx_ctl:print("process/~-16s: ~w~n", [Name, erlang:system_info(Key)]) || {Name, Key} <- [{limit, process_limit}, {count, process_count}]]; [emqx_ctl:print("process/~-16s: ~w~n", [Name, erlang:system_info(Key)])
|| {Name, Key} <- [{limit, process_limit}, {count, process_count}]];
vm(["io"]) -> vm(["io"]) ->
IoInfo = lists:usort(lists:flatten(erlang:system_info(check_io))), IoInfo = lists:usort(lists:flatten(erlang:system_info(check_io))),
[emqx_ctl:print("io/~-21s: ~w~n", [Key, proplists:get_value(Key, IoInfo)]) || Key <- [max_fds, active_fds]]; [emqx_ctl:print("io/~-21s: ~w~n", [Key, proplists:get_value(Key, IoInfo)])
|| Key <- [max_fds, active_fds]];
vm(["ports"]) -> vm(["ports"]) ->
[emqx_ctl:print("ports/~-18s: ~w~n", [Name, erlang:system_info(Key)]) || {Name, Key} <- [{count, port_count}, {limit, port_limit}]]; [emqx_ctl:print("ports/~-18s: ~w~n", [Name, erlang:system_info(Key)])
|| {Name, Key} <- [{count, port_count}, {limit, port_limit}]];
vm(_) -> vm(_) ->
emqx_ctl:usage([{"vm all", "Show info of Erlang VM"}, emqx_ctl:usage([{"vm all", "Show info of Erlang VM"},
@ -323,8 +329,14 @@ log(["primary-level", Level]) ->
emqx_ctl:print("~ts~n", [emqx_logger:get_primary_log_level()]); emqx_ctl:print("~ts~n", [emqx_logger:get_primary_log_level()]);
log(["handlers", "list"]) -> log(["handlers", "list"]) ->
_ = [emqx_ctl:print("LogHandler(id=~ts, level=~ts, destination=~ts, status=~ts)~n", [Id, Level, Dst, Status]) _ = [emqx_ctl:print(
|| #{id := Id, level := Level, dst := Dst, status := Status} <- emqx_logger:get_log_handlers()], "LogHandler(id=~ts, level=~ts, destination=~ts, status=~ts)~n",
[Id, Level, Dst, Status]
)
|| #{id := Id,
level := Level,
dst := Dst,
status := Status} <- emqx_logger:get_log_handlers()],
ok; ok;
log(["handlers", "start", HandlerId]) -> log(["handlers", "start", HandlerId]) ->
@ -351,21 +363,25 @@ log(["handlers", "set-level", HandlerId, Level]) ->
end; end;
log(_) -> log(_) ->
emqx_ctl:usage([{"log set-level <Level>", "Set the overall log level"}, emqx_ctl:usage(
{"log primary-level", "Show the primary log level now"}, [{"log set-level <Level>", "Set the overall log level"},
{"log primary-level <Level>","Set the primary log level"}, {"log primary-level", "Show the primary log level now"},
{"log handlers list", "Show log handlers"}, {"log primary-level <Level>","Set the primary log level"},
{"log handlers start <HandlerId>", "Start a log handler"}, {"log handlers list", "Show log handlers"},
{"log handlers stop <HandlerId>", "Stop a log handler"}, {"log handlers start <HandlerId>", "Start a log handler"},
{"log handlers set-level <HandlerId> <Level>", "Set log level of a log handler"}]). {"log handlers stop <HandlerId>", "Stop a log handler"},
{"log handlers set-level <HandlerId> <Level>", "Set log level of a log handler"}]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Trace Command %% @doc Trace Command
trace(["list"]) -> trace(["list"]) ->
lists:foreach(fun({{Who, Name}, {Level, LogFile}}) -> lists:foreach(fun({{Who, Name}, {Level, LogFile}}) ->
emqx_ctl:print("Trace(~ts=~ts, level=~ts, destination=~p)~n", [Who, Name, Level, LogFile]) emqx_ctl:print(
end, emqx_tracer:lookup_traces()); "Trace(~ts=~ts, level=~ts, destination=~p)~n",
[Who, Name, Level, LogFile]
)
end, emqx_tracer:lookup_traces());
trace(["stop", "client", ClientId]) -> trace(["stop", "client", ClientId]) ->
trace_off(clientid, ClientId); trace_off(clientid, ClientId);
@ -489,10 +505,11 @@ authz(["cache-clean", ClientId]) ->
emqx_mgmt:clean_authz_cache(ClientId); emqx_mgmt:clean_authz_cache(ClientId);
authz(_) -> authz(_) ->
emqx_ctl:usage([{"authz cache-clean all", "Clears authorization cache on all nodes"}, emqx_ctl:usage(
{"authz cache-clean node <Node>", "Clears authorization cache on given node"}, [{"authz cache-clean all", "Clears authorization cache on all nodes"},
{"authz cache-clean <ClientId>", "Clears authorization cache for given client"} {"authz cache-clean node <Node>", "Clears authorization cache on given node"},
]). {"authz cache-clean <ClientId>", "Clears authorization cache for given client"}
]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -560,23 +577,24 @@ print({client, {ClientId, ChanPid}}) ->
maps:with([peername, clean_start, keepalive, expiry_interval, maps:with([peername, clean_start, keepalive, expiry_interval,
connected_at, disconnected_at], ConnInfo), connected_at, disconnected_at], ConnInfo),
maps:with([created_at], Session)]), maps:with([created_at], Session)]),
InfoKeys = [clientid, username, peername, InfoKeys = [clientid, username, peername, clean_start, keepalive,
clean_start, keepalive, expiry_interval, expiry_interval, subscriptions_cnt, inflight_cnt,
subscriptions_cnt, inflight_cnt, awaiting_rel_cnt, send_msg, mqueue_len, mqueue_dropped, awaiting_rel_cnt, send_msg, mqueue_len, mqueue_dropped,
connected, created_at, connected_at] ++ connected, created_at, connected_at] ++
case maps:is_key(disconnected_at, Info) of case maps:is_key(disconnected_at, Info) of
true -> [disconnected_at]; true -> [disconnected_at];
false -> [] false -> []
end, end,
Info1 = Info#{expiry_interval => maps:get(expiry_interval, Info) div 1000}, Info1 = Info#{expiry_interval => maps:get(expiry_interval, Info) div 1000},
emqx_ctl:print("Client(~ts, username=~ts, peername=~ts, " emqx_ctl:print(
"clean_start=~ts, keepalive=~w, session_expiry_interval=~w, " "Client(~ts, username=~ts, peername=~ts, clean_start=~ts, "
"subscriptions=~w, inflight=~w, awaiting_rel=~w, delivered_msgs=~w, enqueued_msgs=~w, dropped_msgs=~w, " "keepalive=~w, session_expiry_interval=~w, subscriptions=~w, "
"connected=~ts, created_at=~w, connected_at=~w" ++ "inflight=~w, awaiting_rel=~w, delivered_msgs=~w, enqueued_msgs=~w, "
case maps:is_key(disconnected_at, Info1) of "dropped_msgs=~w, connected=~ts, created_at=~w, connected_at=~w"
true -> ", disconnected_at=~w)~n"; ++ case maps:is_key(disconnected_at, Info1) of
false -> ")~n" true -> ", disconnected_at=~w)~n";
end, false -> ")~n"
end,
[format(K, maps:get(K, Info1)) || K <- InfoKeys]); [format(K, maps:get(K, Info1)) || K <- InfoKeys]);
print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) -> print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) ->