@@ -179,6 +179,11 @@ handle_event(
179179 # rabbit_cli {arg_map = #{help := true }} = Context ) ->
180180 display_help (Context ),
181181 {stop , {shutdown , ok }, Context };
182+ handle_event (
183+ internal , run_command , command_parsed ,
184+ # rabbit_cli {arg_map = #{version := true }} = Context ) ->
185+ display_version (Context ),
186+ {stop , {shutdown , ok }, Context };
182187handle_event (internal , run_command , command_parsed , Context ) ->
183188 Ret = do_run_command (Context ),
184189 {stop , {shutdown , Ret }, Context }.
@@ -252,3 +257,31 @@ display_help(#rabbit_cli{progname = Progname,
252257 Help = argparse :help (ArgparseDef , Options ),
253258 io :format (" ~s~n " , [Help ]),
254259 ok .
260+
261+ display_version (_Context ) ->
262+ case application :get_key (rabbit , vsn ) of
263+ {ok , _ } ->
264+ ProductInfo = rabbit :product_info (),
265+ ProductName = maps :get (
266+ product_name , ProductInfo ,
267+ maps :get (product_base_name , ProductInfo )),
268+ ProductVersion = maps :get (
269+ product_version , ProductInfo ,
270+ maps :get (product_base_version , ProductInfo )),
271+ OtpRelease = maps :get (otp_release , ProductInfo ),
272+ State = rabbit_boot_state :get (),
273+ io :format (
274+ " ~ts ~ts~n "
275+ " Erlang/OTP ~ts~n "
276+ " Status: ~ts~n " ,
277+ [ProductName , ProductVersion , OtpRelease , State ]);
278+ _ ->
279+ OtpRelease = erlang :system_info (otp_release ),
280+ ok = application :load (rabbit ),
281+ {ok , Vsn } = application :get_key (rabbit , vsn ),
282+ io :format (
283+ " RabbitMQ ~ts~n "
284+ " Erlang/OTP ~ts~n "
285+ " Status: (not connected to a RabbitMQ node)~n " ,
286+ [Vsn , OtpRelease ])
287+ end .
0 commit comments