diff options
| author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2010-08-03 09:59:27 +0100 |
|---|---|---|
| committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2010-08-03 09:59:27 +0100 |
| commit | 6deac66223691400e460ed1fb0b88aad289318f7 (patch) | |
| tree | 0519aedd947748264a8db29838bb70a389c4bc22 /src | |
| parent | ee4fa13e7a2a043a2a4840b8f2e04f5742115d3e (diff) | |
| download | rabbitmq-server-git-6deac66223691400e460ed1fb0b88aad289318f7.tar.gz | |
treat no-arguments-given as a special case; refactored opt parser
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_control.erl | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index cb19485efc..a36dc79ba9 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -60,6 +60,10 @@ start() -> {ok, [[NodeStr|_]|_]} = init:get_argument(nodename), FullCommand = init:get_plain_arguments(), + case FullCommand of + [] -> usage(); + _ -> ok + end, {[Command0 | Args], Opts} = get_options([{flag, ?QUIET_OPT}, {option, ?NODE_OPT, NodeStr}, {option, ?VHOST_OPT, "/"}, {option, ?SCOPE_OPT, "client"}], @@ -70,9 +74,7 @@ start() -> _ -> {K, V} end end, Opts), - io:format("~p~n", [Opts1]), Command = list_to_atom(Command0), - io:format("~p~n", [[Command | Args]]), Quiet = proplists:get_bool(?QUIET_OPT, Opts1), Node = proplists:get_value(?NODE_OPT, Opts1), Inform = case Quiet of @@ -388,16 +390,16 @@ prettify_typed_amqp_value(Type, Value) -> % "-q",".*",".*",".*"]) % == {["set_permissions","guest",".*",".*",".*"], % [{"-q",true},{"-p","/"}]} -get_options([{flag, Key} | Defs], As) -> - {As1, Value} = get_flag(Key, As), - {As2, Rest} = get_options(Defs, As1), - {As2, [{Key, Value} | Rest]}; -get_options([{option, Key, Default} | Defs], As) -> - {As1, Value} = get_option(Key, Default, As), - {As2, Rest} = get_options(Defs, As1), - {As2, [{Key, Value} | Rest]}; -get_options([], As) -> - {As, []}. +get_options(Defs, As) -> + lists:foldl(fun(Def, {AsIn, RsIn}) -> + {AsOut, Value} = case Def of + {flag, Key} -> + get_flag(Key, AsIn); + {option, Key, Default} -> + get_option(Key, Default, AsIn) + end, + {AsOut, [{Key, Value} | RsIn]} + end, {As, []}, Defs). get_option(K, _Default, [K, V | As]) -> {As, V}; |
