diff options
| -rw-r--r-- | src/rabbit_plugin.erl | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/rabbit_plugin.erl b/src/rabbit_plugin.erl index 6d94cee73a..b271652bee 100644 --- a/src/rabbit_plugin.erl +++ b/src/rabbit_plugin.erl @@ -19,6 +19,8 @@ -export([start/0, stop/0]). +-define(FORCE_OPT, "-f"). + %%---------------------------------------------------------------------------- -ifdef(use_specs). @@ -31,11 +33,40 @@ %%---------------------------------------------------------------------------- start() -> - io:format("Rabbitmq-plugin, GO!~n"), + {[Command0 | Args], Opts} = + case rabbit_misc:get_options([{flag, ?FORCE_OPT}], + init:get_plain_arguments()) of + {[], _Opts} -> usage(); + CmdArgsAndOpts -> CmdArgsAndOpts + end, + Command = list_to_atom(Command0), - rabbit_misc:quit(0). + case catch action(Command, Args, Opts) of + ok -> + rabbit_misc:quit(0); + {'EXIT', {function_clause, [{?MODULE, action, _} | _]}} -> + print_error("invalid command '~s'", + [string:join([atom_to_list(Command) | Args], " ")]), + usage(); + {error, Reason} -> + print_error("~p", [Reason]), + rabbit_misc:quit(2); + Other -> + print_error("~p", [Other]), + rabbit_misc:quit(2) + end. stop() -> ok. +print_error(Format, Args) -> + rabbit_misc:format_stderr("Error: " ++ Format ++ "~n", Args). + +usage() -> + io:format("Insert USAGE here.~n"), + rabbit_misc:quit(1). + %%---------------------------------------------------------------------------- + +action(test, [], _Opts) -> + io:format("Test ok~n"). |
