24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-18 22:15:20 +02:00

ejabberd_ctl: Improve printing lists in results

When formatting the results of a command:
- If the top of the result is a list, split elements with newline as usual
- If it's a list in one of the resulting lines, split elements with ;
This commit is contained in:
Badlop 2023-09-21 12:23:13 +02:00
parent 739a231259
commit 8d39431d68

View File

@ -335,7 +335,7 @@ call_command([CmdString | Args], Auth, _AccessCommands, Version) ->
ArgsFormatted, ArgsFormatted,
CI2, CI2,
Version), Version),
format_result(Result, ResultFormat); format_result_preliminary(Result, ResultFormat);
{'EXIT', {function_clause,[{lists,zip,[A1,A2|_], _} | _]}} -> {'EXIT', {function_clause,[{lists,zip,[A1,A2|_], _} | _]}} ->
{NumCompa, TextCompa} = {NumCompa, TextCompa} =
case {length(A1), length(A2)} of case {length(A1), length(A2)} of
@ -385,6 +385,11 @@ format_arg2(Arg, Parse)->
%% Format result %% Format result
%%----------------------------- %%-----------------------------
format_result_preliminary(Result, {A, {list, B}}) ->
format_result(Result, {A, {top_result_list, B}});
format_result_preliminary(Result, ResultFormat) ->
format_result(Result, ResultFormat).
format_result({error, ErrorAtom}, _) -> format_result({error, ErrorAtom}, _) ->
{io_lib:format("Error: ~p", [ErrorAtom]), make_status(error)}; {io_lib:format("Error: ~p", [ErrorAtom]), make_status(error)};
@ -421,6 +426,16 @@ format_result(Code, {_Name, rescode}) ->
format_result({Code, Text}, {_Name, restuple}) -> format_result({Code, Text}, {_Name, restuple}) ->
{io_lib:format("~ts", [Text]), make_status(Code)}; {io_lib:format("~ts", [Text]), make_status(Code)};
format_result([], {_Name, {top_result_list, _ElementsDef}}) ->
"";
format_result([FirstElement | Elements], {_Name, {top_result_list, ElementsDef}}) ->
[format_result(FirstElement, ElementsDef) |
lists:map(
fun(Element) ->
["\n" | format_result(Element, ElementsDef)]
end,
Elements)];
%% The result is a list of something: [something()] %% The result is a list of something: [something()]
format_result([], {_Name, {list, _ElementsDef}}) -> format_result([], {_Name, {list, _ElementsDef}}) ->
""; "";
@ -430,7 +445,7 @@ format_result([FirstElement | Elements], {_Name, {list, ElementsDef}}) ->
%% If there are more elements, put always first a newline character %% If there are more elements, put always first a newline character
lists:map( lists:map(
fun(Element) -> fun(Element) ->
["\n" | format_result(Element, ElementsDef)] [";" | format_result(Element, ElementsDef)]
end, end,
Elements)]; Elements)];
@ -755,7 +770,10 @@ print_usage_help(MaxC, ShCode) ->
"\n", "\n",
"Please note that 'ejabberdctl' shows all ejabberd commands,\n", "Please note that 'ejabberdctl' shows all ejabberd commands,\n",
"even those that cannot be used in the shell with ejabberdctl.\n", "even those that cannot be used in the shell with ejabberdctl.\n",
"Those commands can be identified because their description starts with: *"], "Those commands can be identified because their description starts with: *\n",
"\n",
"Some commands return lists, like get_roster and get_user_subscriptions.\n",
"In those commands, the elements in the list are separated with: ;\n"],
ArgsDef = [], ArgsDef = [],
C = #ejabberd_commands{ C = #ejabberd_commands{
name = help, name = help,