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
|
unload/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-include_lib("hocon/include/hoconsc.hrl").
|
||||||
|
|
||||||
%% kept cluster_call for compatibility
|
%% kept cluster_call for compatibility
|
||||||
-define(CLUSTER_CALL, cluster_call).
|
-define(CLUSTER_CALL, cluster_call).
|
||||||
-define(CONF, conf).
|
-define(CONF, conf).
|
||||||
|
@ -34,8 +36,8 @@ unload() ->
|
||||||
emqx_ctl:unregister_command(?CLUSTER_CALL),
|
emqx_ctl:unregister_command(?CLUSTER_CALL),
|
||||||
emqx_ctl:unregister_command(?CONF).
|
emqx_ctl:unregister_command(?CONF).
|
||||||
|
|
||||||
conf(["show", "--keys-only"]) ->
|
conf(["show_keys" | _]) ->
|
||||||
print(emqx_config:get_root_names());
|
print_keys(get_config());
|
||||||
conf(["show"]) ->
|
conf(["show"]) ->
|
||||||
print_hocon(get_config());
|
print_hocon(get_config());
|
||||||
conf(["show", Key]) ->
|
conf(["show", Key]) ->
|
||||||
|
@ -87,9 +89,10 @@ usage_conf() ->
|
||||||
[
|
[
|
||||||
%% TODO add reload
|
%% TODO add reload
|
||||||
%{"conf reload", "reload etc/emqx.conf on local node"},
|
%{"conf reload", "reload etc/emqx.conf on local node"},
|
||||||
{"conf show --keys-only", "Print all config keys"},
|
{"conf show_keys", "Print all config keys"},
|
||||||
{"conf show", "Print config in use"},
|
{"conf show [<key>]",
|
||||||
{"conf show <key>", "Print configs under the given key"},
|
"Print in-use configs (including default values) under the given key. "
|
||||||
|
"Print ALL keys if key is not provided"},
|
||||||
{"conf load <path>",
|
{"conf load <path>",
|
||||||
"Load a HOCON format config file."
|
"Load a HOCON format config file."
|
||||||
"The config is overlay on top of the existing configs. "
|
"The config is overlay on top of the existing configs. "
|
||||||
|
@ -100,13 +103,13 @@ usage_conf() ->
|
||||||
|
|
||||||
usage_sync() ->
|
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 skip [node]", "Increase one commit on specific node"},
|
||||||
{"conf cluster_sync tnxid <TnxId>",
|
{"conf cluster_sync tnxid <TnxId>",
|
||||||
"Display detailed information of the config change transaction at TnxId"},
|
"Display detailed information of the config change transaction at TnxId"},
|
||||||
{"conf cluster_sync fast_forward [node] [tnx_id]",
|
{"conf cluster_sync fast_forward [node] [tnx_id]",
|
||||||
"Fast-forward config change transaction to tnx_id on the given node."
|
"Fast-forward config change transaction to tnx_id on the given node."
|
||||||
"WARNING: This results in inconsistent configs among the clustered nodes."}
|
"WARNING: This results in inconsistent configs among the clustered nodes."}
|
||||||
].
|
].
|
||||||
|
|
||||||
status() ->
|
status() ->
|
||||||
|
@ -129,14 +132,39 @@ status() ->
|
||||||
),
|
),
|
||||||
emqx_ctl:print("-----------------------------------------------\n").
|
emqx_ctl:print("-----------------------------------------------\n").
|
||||||
|
|
||||||
|
print_keys(Config) ->
|
||||||
|
print(lists:sort(maps:keys(Config))).
|
||||||
|
|
||||||
print(Json) ->
|
print(Json) ->
|
||||||
emqx_ctl:print("~ts~n", [emqx_logger_jsonfmt:best_effort_json(Json)]).
|
emqx_ctl:print("~ts~n", [emqx_logger_jsonfmt:best_effort_json(Json)]).
|
||||||
|
|
||||||
print_hocon(Hocon) ->
|
print_hocon(Hocon) ->
|
||||||
emqx_ctl:print("~ts~n", [hocon_pp:do(Hocon, #{})]).
|
emqx_ctl:print("~ts~n", [hocon_pp:do(Hocon, #{})]).
|
||||||
|
|
||||||
get_config() -> emqx_config:fill_defaults(emqx:get_raw_config([])).
|
get_config() ->
|
||||||
get_config(Key) -> emqx_config:fill_defaults(#{Key => emqx:get_raw_config([Key])}).
|
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}).
|
-define(OPTIONS, #{rawconf_with_defaults => true, override_to => cluster}).
|
||||||
load_config(Path) ->
|
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