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.ServerVersionCommand do
8  @behaviour RabbitMQ.CLI.CommandBehaviour
9
10  use RabbitMQ.CLI.Core.AcceptsDefaultSwitchesAndTimeout
11  use RabbitMQ.CLI.Core.MergesNoDefaults
12  use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
13
14  def run([], %{node: node_name, timeout: timeout}) do
15    :rabbit_data_coercion.to_binary(
16      :rabbit_misc.rpc_call(node_name, :rabbit_misc, :version, [], timeout))
17  end
18
19  def output(result, %{formatter: "json"}) do
20    {:ok, %{"result" => "ok", "value" => result}}
21  end
22  def output(result, _options) when is_bitstring(result) do
23    {:ok, result}
24  end
25
26  use RabbitMQ.CLI.DefaultOutput
27
28  def help_section(), do: :observability_and_health_checks
29
30  def description(), do: "Displays server version on the target node"
31
32  def usage, do: "server_version"
33
34  def banner([], %{node: node_name}) do
35    "Asking node #{node_name} for its RabbitMQ version..."
36  end
37end
38