refactor(emqx_conf_cli): do not print hidden roots in 'conf show' cmd
This commit is contained in:
parent
31ab973b30
commit
83c36a3c9f
|
@ -22,6 +22,8 @@
|
|||
unload/0
|
||||
]).
|
||||
|
||||
-include_lib("hocon/include/hoconsc.hrl").
|
||||
|
||||
%% kept cluster_call for compatibility
|
||||
-define(CLUSTER_CALL, cluster_call).
|
||||
-define(CONF, conf).
|
||||
|
@ -34,8 +36,8 @@ unload() ->
|
|||
emqx_ctl:unregister_command(?CLUSTER_CALL),
|
||||
emqx_ctl:unregister_command(?CONF).
|
||||
|
||||
conf(["show", "--keys-only"]) ->
|
||||
print(emqx_config:get_root_names());
|
||||
conf(["show_keys" | _]) ->
|
||||
print_keys(get_config());
|
||||
conf(["show"]) ->
|
||||
print_hocon(get_config());
|
||||
conf(["show", Key]) ->
|
||||
|
@ -87,9 +89,10 @@ usage_conf() ->
|
|||
[
|
||||
%% TODO add reload
|
||||
%{"conf reload", "reload etc/emqx.conf on local node"},
|
||||
{"conf show --keys-only", "Print all config keys"},
|
||||
{"conf show", "Print config in use"},
|
||||
{"conf show <key>", "Print configs under the given key"},
|
||||
{"conf show_keys", "Print all config keys"},
|
||||
{"conf show [<key>]",
|
||||
"Print in-use configs (including default values) under the given key. "
|
||||
"Print ALL keys if key is not provided"},
|
||||
{"conf load <path>",
|
||||
"Load a HOCON format config file."
|
||||
"The config is overlay on top of the existing configs. "
|
||||
|
@ -100,7 +103,7 @@ usage_conf() ->
|
|||
|
||||
usage_sync() ->
|
||||
[
|
||||
{"conf cluster_sync tatus", "Show cluster config sync status summary"},
|
||||
{"conf cluster_sync status", "Show cluster config sync status summary"},
|
||||
{"conf cluster_sync skip [node]", "Increase one commit on specific node"},
|
||||
{"conf cluster_sync tnxid <TnxId>",
|
||||
"Display detailed information of the config change transaction at TnxId"},
|
||||
|
@ -129,14 +132,39 @@ status() ->
|
|||
),
|
||||
emqx_ctl:print("-----------------------------------------------\n").
|
||||
|
||||
print_keys(Config) ->
|
||||
print(lists:sort(maps:keys(Config))).
|
||||
|
||||
print(Json) ->
|
||||
emqx_ctl:print("~ts~n", [emqx_logger_jsonfmt:best_effort_json(Json)]).
|
||||
|
||||
print_hocon(Hocon) ->
|
||||
emqx_ctl:print("~ts~n", [hocon_pp:do(Hocon, #{})]).
|
||||
|
||||
get_config() -> emqx_config:fill_defaults(emqx:get_raw_config([])).
|
||||
get_config(Key) -> emqx_config:fill_defaults(#{Key => emqx:get_raw_config([Key])}).
|
||||
get_config() ->
|
||||
drop_hidden_roots(emqx_config:fill_defaults(emqx:get_raw_config([]))).
|
||||
|
||||
drop_hidden_roots(Conf) ->
|
||||
Hidden = hidden_roots(),
|
||||
maps:without(Hidden, Conf).
|
||||
|
||||
hidden_roots() ->
|
||||
SchemaModule = emqx_conf:schema_module(),
|
||||
Roots = hocon_schema:roots(SchemaModule),
|
||||
lists:filtermap(
|
||||
fun({BinName, {_RefName, Schema}}) ->
|
||||
case hocon_schema:field_schema(Schema, importance) =/= ?IMPORTANCE_HIDDEN of
|
||||
true ->
|
||||
false;
|
||||
false ->
|
||||
{true, BinName}
|
||||
end
|
||||
end,
|
||||
Roots
|
||||
).
|
||||
|
||||
get_config(Key) ->
|
||||
emqx_config:fill_defaults(#{Key => emqx:get_raw_config([Key])}).
|
||||
|
||||
-define(OPTIONS, #{rawconf_with_defaults => true, override_to => cluster}).
|
||||
load_config(Path) ->
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Renamed emqx ctl command 'cluster_call' to 'conf cluster_sync'.
|
||||
The old command 'cluster_call' is still a valid command, but not included in usage info.
|
Loading…
Reference in New Issue