chore: pretty the cli output style
This commit is contained in:
parent
3cd223ff5b
commit
b9f0cd7ba4
|
@ -270,25 +270,37 @@ check_res(Node, Key, {ok, _}, _Conf, _Mode) ->
|
||||||
emqx_ctl:print("load ~ts on ~p ok~n", [Key, Node]),
|
emqx_ctl:print("load ~ts on ~p ok~n", [Key, Node]),
|
||||||
ok;
|
ok;
|
||||||
check_res(_Node, Key, {error, Reason}, Conf, Mode) ->
|
check_res(_Node, Key, {error, Reason}, Conf, Mode) ->
|
||||||
Warning = io_lib:format("~ts ~ts failed~n~p~n", [Mode, Key, Reason]),
|
Warning =
|
||||||
emqx_ctl:warning(Warning, []),
|
"Can't ~ts the new configurations!~n"
|
||||||
ActiveMsg = "--------active configuration--------\n",
|
"Root key: ~ts~n"
|
||||||
Active = hocon_pp:do(#{Key => emqx_conf:get_raw([Key])}, #{}),
|
"Reason: ~p~n",
|
||||||
FailedMsg = io_lib:format("--------failed to ~ts with----------~n", [Mode]),
|
emqx_ctl:warning(Warning, [Mode, Key, Reason]),
|
||||||
New = hocon_pp:do(#{Key => Conf}, #{}),
|
ActiveMsg0 =
|
||||||
|
"The effective configurations:~n"
|
||||||
|
"```~n"
|
||||||
|
"~ts```~n~n",
|
||||||
|
ActiveMsg = io_lib:format(ActiveMsg0, [hocon_pp:do(#{Key => emqx_conf:get_raw([Key])}, #{})]),
|
||||||
|
FailedMsg0 =
|
||||||
|
"Try to ~ts with:~n"
|
||||||
|
"```~n"
|
||||||
|
"~ts```~n",
|
||||||
|
FailedMsg = io_lib:format(FailedMsg0, [Mode, hocon_pp:do(#{Key => Conf}, #{})]),
|
||||||
SuggestMsg = suggest_msg(Mode),
|
SuggestMsg = suggest_msg(Mode),
|
||||||
Msg = iolist_to_binary([ActiveMsg, Active, FailedMsg, New, SuggestMsg]),
|
Msg = iolist_to_binary([ActiveMsg, FailedMsg, SuggestMsg]),
|
||||||
emqx_ctl:print("~ts", [Msg]),
|
emqx_ctl:print("~ts", [Msg]),
|
||||||
{error, iolist_to_binary([Warning, Msg])}.
|
{error, iolist_to_binary([Warning, Msg])}.
|
||||||
|
|
||||||
suggest_msg(merge) ->
|
suggest_msg(Mode) when Mode == merge orelse Mode == replace ->
|
||||||
"Merge conflict with the active Key.\n"
|
RetryMode =
|
||||||
"Suggest to use the replace option to completely replace the configuration,\n"
|
case Mode of
|
||||||
"instead of merging conflict.\n\n";
|
merge -> "replace";
|
||||||
suggest_msg(replace) ->
|
replace -> "merge"
|
||||||
"Replace failed with an incomplete configuration.\n"
|
end,
|
||||||
"Suggest to use the merge option to only update sub configuration,\n"
|
io_lib:format(
|
||||||
"instead of replacing with an incomplete configuration.\n\n".
|
"Tips: There may be some conflicts in the new configuration under `~ts` mode,~n"
|
||||||
|
"Please retry with the `~ts` mode.~n",
|
||||||
|
[Mode, RetryMode]
|
||||||
|
).
|
||||||
|
|
||||||
check_config(Conf) ->
|
check_config(Conf) ->
|
||||||
case check_keys_is_not_readonly(Conf) of
|
case check_keys_is_not_readonly(Conf) of
|
||||||
|
|
Loading…
Reference in New Issue