1## This Source Code Form is subject to the terms of the Mozilla Public 2## License, v. 2.0. If a copy of the MPL was not distributed with this 3## file, You can obtain one at https://mozilla.org/MPL/2.0/. 4## 5## Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved. 6 7defmodule RabbitMQ.CLI.Diagnostics.Commands.ErlangVersionCommand do 8 @behaviour RabbitMQ.CLI.CommandBehaviour 9 10 def switches() do 11 [details: :boolean, offline: :boolean, timeout: :integer] 12 end 13 def aliases(), do: [t: :timeout] 14 15 def merge_defaults(args, opts) do 16 {args, Map.merge(%{details: false, offline: false}, opts)} 17 end 18 19 use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments 20 21 def run([], %{details: details, offline: true}) do 22 case details do 23 true -> 24 :rabbit_data_coercion.to_binary( 25 :rabbit_misc.otp_system_version()) 26 27 false -> 28 :rabbit_data_coercion.to_binary( 29 :rabbit_misc.platform_and_version()) 30 end 31 end 32 def run([], %{node: node_name, timeout: timeout, details: details}) do 33 case details do 34 true -> 35 :rabbit_data_coercion.to_binary( 36 :rabbit_misc.rpc_call(node_name, :rabbit_misc, :otp_system_version, [], timeout)) 37 38 false -> 39 :rabbit_data_coercion.to_binary( 40 :rabbit_misc.rpc_call(node_name, :rabbit_misc, :platform_and_version, [], timeout)) 41 end 42 end 43 44 def output(result, %{formatter: "json"}) do 45 {:ok, %{"result" => "ok", "value" => result}} 46 end 47 def output(result, _opts) when is_bitstring(result) do 48 {:ok, result} 49 end 50 51 use RabbitMQ.CLI.DefaultOutput 52 53 def help_section(), do: :observability_and_health_checks 54 55 def description(), do: "Displays Erlang/OTP version on the target node" 56 57 def usage, do: "erlang_version" 58 59 def usage_additional() do 60 [ 61 ["--details", "when set, display additional Erlang/OTP system information"], 62 ["--offline", "when set, displays local Erlang/OTP version (that used by CLI tools)"] 63 ] 64 end 65 66 def banner([], %{offline: true}) do 67 "CLI Erlang/OTP version ..." 68 end 69 def banner([], %{node: node_name}) do 70 "Asking node #{node_name} for its Erlang/OTP version..." 71 end 72end 73