Skip to content

Commit 5be8843

Browse files
committed
wip
1 parent 46f7e2d commit 5be8843

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

deps/rabbit/src/rabbit_cli.erl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,25 @@ get_rabbitmq_nodename_from_args(Args) ->
5050
action => count,
5151
help =>
5252
"Be verbose; can be specified multiple times to "
53-
"increase "
54-
"verbosity"},
53+
"increase verbosity"},
5554
#{name => node,
5655
long => "-node",
5756
short => $n,
5857
type => string,
5958
nargs => 1,
60-
help => "Name of the node to control"},
61-
#{name => rest,
62-
nargs => list,
63-
action => extend,
64-
required => false,
65-
default => []}]},
66-
case argparse:parse(Args, Definition, #{}) of
67-
{ok, #{node := Nodename, rest := Rest}, _, _} ->
59+
help => "Name of the node to control"}]},
60+
?LOG_ALERT("argparse 1: ~p", [Definition]),
61+
case rabbit_cli_io:parse(Args, Definition) of
62+
{ok, #{node := Nodename} = _ArgMap, _, _, Rest} ->
63+
?LOG_ALERT("argparse 1: ~p, ~p", [_ArgMap, Rest]),
6864
{ok, {Nodename, Rest}};
69-
{ok, #{rest := Rest}, _, _} ->
65+
{ok, #{rest := Rest} = _ArgMap, _, _} ->
66+
?LOG_ALERT("argparse 1: ~p", [_ArgMap]),
7067
{ok, Rest};
7168
{error, {_, #{name := node}, _, ErrorMsg}} ->
7269
{error, ErrorMsg};
73-
{error, _} ->
70+
{error, _} = _Error->
71+
?LOG_ALERT("argparse 1: ~p", [_Error]),
7472
{ok, Args}
7573
end.
7674

deps/rabbit/src/rabbit_cli_commands.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ commands() ->
1717
required => false,
1818
default => []}
1919
],
20-
commands =>
20+
xcommands =>
2121
#{
2222
"list" =>
2323
#{
@@ -33,16 +33,19 @@ commands() ->
3333

3434
run_command(Args, IO) ->
3535
Definition = commands(),
36+
?LOG_ALERT("argparse 2: ~p", [Definition]),
3637
case argparse:parse(Args, Definition, #{}) of
3738
{ok, ArgMap, _CmdPath, Command} ->
39+
?LOG_ALERT("argparse 2: ~p", [ArgMap]),
3840
%% TODO: Put both processes under the rabbit supervision tree.
3941
RunnerPid = command_runner(Command, ArgMap, IO),
4042
RunnerMRef = erlang:monitor(process, RunnerPid),
4143
receive
4244
{'DOWN', RunnerMRef, _, _, Reason} ->
4345
{ok, Reason}
4446
end;
45-
{error, _Reason} = Error ->
47+
{error, Reason} = Error ->
48+
?LOG_ALERT("Error: ~s", [argparse:format_error(Reason)]),
4649
Error
4750
end.
4851

deps/rabbit/src/rabbit_cli_io.erl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
-include_lib("rabbit_common/include/resource.hrl").
66

7+
-export([parse/2]).
78
-export([start_link/0,
89
stop/1,
910
start_record_stream/4,
@@ -18,6 +19,22 @@
1819

1920
-record(?MODULE, {record_streams = #{}}).
2021

22+
parse(Args, Definition) ->
23+
parse(Args, Definition, []).
24+
25+
parse(Args, Definition, Unknown) ->
26+
case argparse:parse(Args, Definition, #{}) of
27+
{ok, ArgMap, CmdPath, Command} ->
28+
Unknown1 = lists:reverse(Unknown),
29+
{ok, ArgMap, CmdPath, Command, Unknown1};
30+
{error, {_CmdPath, undefined, Arg, <<>>}} ->
31+
Args1 = Args -- [Arg],
32+
Unknown1 = [Arg | Unknown],
33+
parse(Args1, Definition, Unknown1);
34+
{error, _} = Error ->
35+
Error
36+
end.
37+
2138
start_link() ->
2239
gen_server:start_link(rabbit_cli_io, none, []).
2340

0 commit comments

Comments
 (0)