Skip to content

Commit ad1525d

Browse files
committed
WIP
1 parent 507b07e commit ad1525d

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

deps/rabbit/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
150150
include ../../rabbitmq-components.mk
151151
include ../../erlang.mk
152152

153+
CLI_SCRIPTS := scripts/rmq3
154+
155+
ebin/$(PROJECT).app:: $(CLI_SCRIPTS)
156+
157+
$(CLI_SCRIPTS): ebin/rabbit_cli_escript.beam
158+
$(gen_verbose) echo '#!/usr/bin/env escript' > "$@"
159+
$(verbose) echo '%%! -start_epmd false' >> "$@"
160+
$(verbose) cat $^ >> "$@"
161+
$(verbose) chmod a+x "$@"
162+
163+
clean:: clean-cli
164+
165+
clean-cli:
166+
$(gen_verbose) rm -f $(CLI_SCRIPTS)
167+
153168
ifeq ($(strip $(BATS)),)
154169
BATS := $(ERLANG_MK_TMP)/bats/bin/bats
155170
endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-module(rabbit_cli_cmd_list_exchanges).
2+
3+
-export([cli/0]).
4+
5+
cli() ->
6+
#{commands => #{
7+
"exchange" => #{
8+
commands => #{
9+
"list" => #{
10+
help => "Lists exchanges",
11+
handler => fun list_exchanges/1
12+
}
13+
},
14+
help => "Provides sub-commands to manage exchanges",
15+
handler => fun(_) -> ok end
16+
},
17+
18+
"list_exchanges" => #{
19+
help => "Lists exchanges",
20+
handler => fun list_exchanges/1
21+
}
22+
}
23+
}.
24+
25+
list_exchanges(Args) ->
26+
Node = get_nodename(Args),
27+
VHost = get_vhost(Args),
28+
InfoKeys = [name, type, durable, auto_delete, internal, arguments, policy],
29+
net_kernel:start([foobar, shortnames]),
30+
io:format("Exchanges on vhost ~p on node ~s~n", [VHost, Node]),
31+
Ret = rpc:call(Node,
32+
rabbit_exchange,
33+
info_all,
34+
[VHost, InfoKeys]),
35+
io:format("~p~n", [Ret]).
36+
37+
get_nodename(#{node := Nodename}) ->
38+
Nodename;
39+
get_nodename(_) ->
40+
#{nodename := Nodename} = rabbit_env:get_context(),
41+
Nodename.
42+
43+
get_vhost(#{vhost := VHost}) ->
44+
VHost;
45+
get_vhost(_) ->
46+
<<"/">>.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-module(rabbit_cli_cmd_version).
2+
3+
-export([cli/0]).
4+
5+
cli() ->
6+
#{commands => #{
7+
"version" => #{
8+
help => "Shows the version of RabbitMQ and exit",
9+
handler => fun show_version/1
10+
}
11+
}
12+
}.
13+
14+
show_version(_) ->
15+
ok = application:load(rabbit),
16+
{ok, Version} = application:get_key(rabbit, vsn),
17+
io:format("~s~n", [Version]).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-module(rabbit_cli_escript).
2+
3+
-export([main/1]).
4+
5+
main(Args) ->
6+
ScriptName = filename:absname(escript:script_name()),
7+
ScriptDir = filename:dirname(ScriptName),
8+
ProgName = list_to_atom(filename:basename(ScriptName, ".bat")),
9+
10+
%% Add RabbitMQ components to Erlang code path.
11+
ErlLibs = filename:join([ScriptDir, "..", "plugins"]),
12+
lists:foreach(
13+
fun(Dir) -> true = code:add_path(Dir) end,
14+
filelib:wildcard(filename:join([ErlLibs, "*", "ebin"]))),
15+
16+
%% Run the CLI.
17+
Mods = [% FIXME: Generate that list.
18+
rabbit_cli_global_options,
19+
rabbit_cli_cmd_list_exchanges,
20+
rabbit_cli_cmd_version
21+
],
22+
cli:run(Args, #{progname => ProgName,
23+
modules => Mods,
24+
warn => suppress}).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-module(rabbit_cli_global_options).
2+
3+
-export([cli/0]).
4+
5+
cli() ->
6+
#{arguments =>
7+
[
8+
#{name => node,
9+
short => $n,
10+
long => "-node",
11+
type => string,
12+
action => store},
13+
14+
#{name => vhost,
15+
short => $v,
16+
long => "-vhost",
17+
type => binary,
18+
action => store},
19+
20+
#{name => verbose,
21+
short => $V,
22+
long => "-verbose",
23+
action => count}
24+
]}.

0 commit comments

Comments
 (0)