From 60fc6e3059051e5aeb3b54d6349a201853bb3083 Mon Sep 17 00:00:00 2001 From: Stefan Strigler Date: Mon, 19 Jun 2023 14:23:03 +0200 Subject: [PATCH] fix cli demo --- emqx-plugin.template | 2 +- src/emqx_cli_demo.erl | 27 --------------------------- src/emqx_plugin_template_app.erl | 3 +++ src/emqx_plugin_template_cli.erl | 12 ++++++++++++ 4 files changed, 16 insertions(+), 28 deletions(-) delete mode 100644 src/emqx_cli_demo.erl create mode 100644 src/emqx_plugin_template_cli.erl diff --git a/emqx-plugin.template b/emqx-plugin.template index 8e872073..aba47892 100644 --- a/emqx-plugin.template +++ b/emqx-plugin.template @@ -14,11 +14,11 @@ {file, "erlang_ls.config", "{{name}}/erlang_ls.config"}. {file, "get-rebar3", "{{name}}/get-rebar3"}. {file, "priv/config.hocon", "{{name}}/priv/config.hocon"}. -{file, "src/emqx_cli_demo.erl", "{{name}}/src/emqx_cli_demo.erl"}. {chmod, "{{name}}/get-rebar3", 8#755}. {template, "README_template.md", "{{name}}/README.md"}. {template, "rebar_template.config", "{{name}}/rebar.config"}. {template, "src/emqx_plugin_template.app.src", "{{name}}/src/{{name}}.app.src"}. {template, "src/emqx_plugin_template.erl", "{{name}}/src/{{name}}.erl"}. {template, "src/emqx_plugin_template_app.erl", "{{name}}/src/{{name}}_app.erl"}. +{template, "src/emqx_plugin_template_cli.erl", "{{name}}/src/{{name}}_cli.erl"}. {template, "src/emqx_plugin_template_sup.erl", "{{name}}/src/{{name}}_sup.erl"}. diff --git a/src/emqx_cli_demo.erl b/src/emqx_cli_demo.erl deleted file mode 100644 index f6415da8..00000000 --- a/src/emqx_cli_demo.erl +++ /dev/null @@ -1,27 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - -%% This is an example on how to extend `emqx ctl` with your own commands. - --module(emqx_cli_demo). - --export([cmd/1]). - -cmd(["arg1", "arg2"]) -> - emqx_ctl:print("ok"); - -cmd(_) -> - emqx_ctl:usage([{"cmd arg1 arg2", "cmd demo"}]). diff --git a/src/emqx_plugin_template_app.erl b/src/emqx_plugin_template_app.erl index 412211e9..e5c1b9f2 100644 --- a/src/emqx_plugin_template_app.erl +++ b/src/emqx_plugin_template_app.erl @@ -12,7 +12,10 @@ start(_StartType, _StartArgs) -> {ok, Sup} = @@name@@_sup:start_link(), @@name@@:load(application:get_all_env()), + + emqx_ctl:register_command(@@name@@, {@@name@@_cli, cmd}), {ok, Sup}. stop(_State) -> + emqx_ctl:unregister_command(@@name@@), @@name@@:unload(). diff --git a/src/emqx_plugin_template_cli.erl b/src/emqx_plugin_template_cli.erl new file mode 100644 index 00000000..fddba192 --- /dev/null +++ b/src/emqx_plugin_template_cli.erl @@ -0,0 +1,12 @@ +{{=@@ @@=}} +-module(@@name@@_cli). + +%% This is an example on how to extend `emqx ctl` with your own commands. + +-export([cmd/1]). + +cmd(["arg1", "arg2"]) -> + emqx_ctl:print("ok"); + +cmd(_) -> + emqx_ctl:usage([{"cmd arg1 arg2", "cmd demo"}]).