diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-09 11:39:42 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-09-09 11:39:42 +0100 |
| commit | ab2f7d3b940f8ab13287faa5057d6047a58abcf4 (patch) | |
| tree | 0a6d3add78d679aa2b17dca70b31a9df84d5366a | |
| parent | 0447b0d9fa031ecff354dfb280ad74d4ce70e99e (diff) | |
| download | rabbitmq-server-git-ab2f7d3b940f8ab13287faa5057d6047a58abcf4.tar.gz | |
comand line parsting for rabbitmq-plugin
| -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"). |
