소스 검색

refactor(emqx_conf_cli): do not print hidden roots in 'conf show' cmd

Zaiming (Stone) Shi 2 년 전
부모
커밋
83c36a3c9f
2개의 변경된 파일39개의 추가작업 그리고 9개의 파일을 삭제
  1. 37 9
      apps/emqx_conf/src/emqx_conf_cli.erl
  2. 2 0
      changes/ce/feat-10985.en.md

+ 37 - 9
apps/emqx_conf/src/emqx_conf_cli.erl

@@ -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,13 +103,13 @@ 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"},
         {"conf cluster_sync fast_forward [node] [tnx_id]",
             "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() ->
@@ -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) ->

+ 2 - 0
changes/ce/feat-10985.en.md

@@ -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.