Browse Source

fix: format the outputs for rule engine CLIs

Shawn 3 years ago
parent
commit
f132b6f6ae

+ 2 - 0
apps/emqx_rule_engine/src/emqx_rule_engine_api.erl

@@ -25,6 +25,8 @@
 
 
 -import(hoconsc, [mk/2, ref/2, array/1]).
 -import(hoconsc, [mk/2, ref/2, array/1]).
 
 
+-export([printable_function_name/2]).
+
 %% Swagger specs from hocon schema
 %% Swagger specs from hocon schema
 -export([api_spec/0, paths/0, schema/1, namespace/0]).
 -export([api_spec/0, paths/0, schema/1, namespace/0]).
 
 

+ 11 - 4
apps/emqx_rule_engine/src/emqx_rule_engine_cli.erl

@@ -84,10 +84,17 @@ pretty_print_rule(ID) ->
     end.
     end.
 
 
 %% erlfmt-ignore
 %% erlfmt-ignore
-format_action(#{func := Func, args := Args}) ->
-    io_lib:format("Function:\n  ~p\n"
-                  "Args:\n  ~p\n"
-                 ,[Func, maps:without([preprocessed_tmpl], Args)]
+format_action(#{mod := Mod, func := Func, args := Args}) ->
+    Name = emqx_rule_engine_api:printable_function_name(Mod, Func),
+    io_lib:format("- Name:  ~s\n"
+                  "  Type:  function\n"
+                  "  Args:  ~p\n"
+                 ,[Name, maps:without([preprocessed_tmpl], Args)]
+                 );
+format_action(BridgeChannelId) when is_binary(BridgeChannelId) ->
+    io_lib:format("- Name:  ~s\n"
+                  "  Type:  data-bridge\n"
+                 ,[BridgeChannelId]
                  ).
                  ).
 
 
 left_pad(Str) ->
 left_pad(Str) ->