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) 2019-2021 VMware, Inc. or its affiliates.  All rights reserved.
6
7defmodule RabbitMQ.CLI.Diagnostics.Commands.LogLocationCommand do
8  @moduledoc """
9  Displays standard log file location on the target node
10  """
11  @behaviour RabbitMQ.CLI.CommandBehaviour
12
13  alias RabbitMQ.CLI.Core.LogFiles
14
15  def switches, do: [all: :boolean, timeout: :integer]
16  def aliases, do: [a: :all, t: :timeout]
17
18  def merge_defaults(args, opts) do
19    {args, Map.merge(%{all: false}, opts)}
20  end
21
22  use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
23
24  def run([], %{node: node_name, timeout: timeout, all: all}) do
25    case all do
26      true  -> LogFiles.get_log_locations(node_name, timeout);
27      false -> LogFiles.get_default_log_location(node_name, timeout)
28    end
29  end
30
31  def output({:ok, location}, %{node: node_name, formatter: "json"}) do
32    {:ok, %{
33      "result" => "ok",
34      "node_name" => node_name,
35      "paths"  => [location]
36    }}
37  end
38  def output(locations, %{node: node_name, formatter: "json"}) do
39    {:ok, %{
40      "result" => "ok",
41      "node_name" => node_name,
42      "paths"  => locations
43    }}
44  end
45  use RabbitMQ.CLI.DefaultOutput
46
47  def help_section(), do: :configuration
48
49  def description(), do: "Shows log file location(s) on target node"
50
51  def usage, do: "log_location [--all|-a]"
52
53  def banner([], %{node: node_name}) do
54    "Log file location(s) on node #{node_name} ..."
55  end
56end
57