2016-03-05 01:42:43 +08:00
|
|
|
## The contents of this file are subject to the Mozilla Public License
|
|
|
|
|
## Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
|
## compliance with the License. You may obtain a copy of the License
|
|
|
|
|
## at http://www.mozilla.org/MPL/
|
|
|
|
|
##
|
|
|
|
|
## Software distributed under the License is distributed on an "AS IS"
|
|
|
|
|
## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
|
## the License for the specific language governing rights and
|
|
|
|
|
## limitations under the License.
|
|
|
|
|
##
|
|
|
|
|
## The Original Code is RabbitMQ.
|
|
|
|
|
##
|
|
|
|
|
## The Initial Developer of the Original Code is GoPivotal, Inc.
|
|
|
|
|
## Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defmodule HelpCommand do
|
|
|
|
|
|
2016-05-05 05:10:41 +08:00
|
|
|
@behaviour CommandBehaviour
|
2016-05-05 03:37:35 +08:00
|
|
|
@flags []
|
2016-05-24 19:33:11 +08:00
|
|
|
def validate(_, _), do: :ok
|
|
|
|
|
def merge_defaults(args, opts), do: {args, opts}
|
2016-05-05 03:37:35 +08:00
|
|
|
|
2016-05-27 05:02:10 +08:00
|
|
|
def switches(), do: []
|
|
|
|
|
|
2016-05-26 07:04:24 +08:00
|
|
|
def run([command_name], _) do
|
|
|
|
|
case Helpers.is_command?(command_name) do
|
|
|
|
|
true ->
|
|
|
|
|
command = Helpers.commands[command_name]
|
|
|
|
|
print_base_usage(command)
|
|
|
|
|
print_options_usage
|
|
|
|
|
print_input_types(command);
|
|
|
|
|
false ->
|
|
|
|
|
all_usage()
|
|
|
|
|
ExitCodes.exit_usage
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-05-26 07:28:20 +08:00
|
|
|
def run(_, _) do
|
2016-05-26 07:04:24 +08:00
|
|
|
all_usage()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def all_usage() do
|
2016-03-05 01:42:43 +08:00
|
|
|
print_base_usage
|
2016-05-26 07:04:24 +08:00
|
|
|
print_options_usage
|
2016-03-05 01:42:43 +08:00
|
|
|
print_commands
|
2016-03-05 06:36:49 +08:00
|
|
|
print_input_types
|
2016-03-23 00:21:12 +08:00
|
|
|
:ok
|
2016-03-05 01:42:43 +08:00
|
|
|
end
|
|
|
|
|
|
2016-05-26 07:04:24 +08:00
|
|
|
def usage(), do: "help <command>"
|
2016-03-05 05:35:54 +08:00
|
|
|
|
2016-03-05 01:42:43 +08:00
|
|
|
defp print_base_usage() do
|
2016-05-26 07:28:20 +08:00
|
|
|
IO.puts "Usage:"
|
|
|
|
|
IO.puts "rabbitmqctl [-n <node>] [-t <timeout>] [-q] <command> [<command options>]"
|
2016-05-26 07:04:24 +08:00
|
|
|
end
|
|
|
|
|
|
2016-05-30 07:17:13 +08:00
|
|
|
def print_base_usage(command) do
|
2016-05-26 07:28:20 +08:00
|
|
|
IO.puts "Usage:"
|
|
|
|
|
IO.puts "rabbitmqctl [-n <node>] [-t <timeout>] [-q] " <>
|
2016-05-26 07:04:24 +08:00
|
|
|
flatten_string(command.usage())
|
|
|
|
|
end
|
2016-03-05 01:42:43 +08:00
|
|
|
|
2016-05-26 07:04:24 +08:00
|
|
|
defp flatten_string(list) when is_list(list) do
|
|
|
|
|
Enum.join(list, "\n")
|
|
|
|
|
end
|
|
|
|
|
defp flatten_string(str) when is_binary(str) do
|
|
|
|
|
str
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp print_options_usage() do
|
|
|
|
|
IO.puts "
|
2016-03-05 01:42:43 +08:00
|
|
|
Options:
|
|
|
|
|
-n node
|
|
|
|
|
-q
|
|
|
|
|
-t timeout
|
|
|
|
|
|
2016-05-05 18:39:27 +08:00
|
|
|
Default node is \"rabbit@server\", where server is the local host. On a host
|
|
|
|
|
named \"server.example.com\", the node name of the RabbitMQ Erlang node will
|
|
|
|
|
usually be rabbit@server (unless RABBITMQ_NODENAME has been set to some
|
|
|
|
|
non-default value at broker startup time). The output of hostname -s is usually
|
|
|
|
|
the correct suffix to use after the \"@\" sign. See rabbitmq-server(1) for
|
2016-03-05 01:42:43 +08:00
|
|
|
details of configuring the RabbitMQ broker.
|
|
|
|
|
|
2016-05-05 18:39:27 +08:00
|
|
|
Quiet output mode is selected with the \"-q\" flag. Informational messages are
|
2016-03-05 01:42:43 +08:00
|
|
|
suppressed when quiet mode is in effect.
|
|
|
|
|
|
2016-05-05 18:39:27 +08:00
|
|
|
Operation timeout in seconds. Only applicable to \"list\" commands. Default is
|
2016-05-26 07:04:24 +08:00
|
|
|
\"infinity\".
|
2016-05-26 07:28:20 +08:00
|
|
|
Some commands accept an optional virtual host parameter for which
|
2016-05-26 07:04:24 +08:00
|
|
|
to display results. The default value is \"/\".\n"
|
2016-03-05 01:42:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp print_commands() do
|
|
|
|
|
IO.puts "Commands:"
|
2016-03-05 06:36:49 +08:00
|
|
|
|
|
|
|
|
# Enum.map obtains the usage string for each command module.
|
|
|
|
|
# Enum.each prints them all.
|
|
|
|
|
Helpers.commands
|
|
|
|
|
|> Map.values
|
2016-05-05 17:26:31 +08:00
|
|
|
|> Enum.map(&(&1.usage))
|
2016-03-30 03:25:26 +08:00
|
|
|
|> List.flatten
|
2016-03-05 06:36:49 +08:00
|
|
|
|> Enum.each(fn(cmd_usage) -> IO.puts " #{cmd_usage}" end)
|
2016-03-22 01:59:22 +08:00
|
|
|
|
2016-03-23 00:21:12 +08:00
|
|
|
:ok
|
2016-03-05 06:36:49 +08:00
|
|
|
end
|
|
|
|
|
|
2016-05-26 07:04:24 +08:00
|
|
|
defp print_input_types(command) do
|
|
|
|
|
if :erlang.function_exported(command, :usage_additional, 0) do
|
|
|
|
|
IO.puts(command.usage_additional())
|
|
|
|
|
else
|
|
|
|
|
:ok
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-03-05 06:36:49 +08:00
|
|
|
|
2016-05-26 07:04:24 +08:00
|
|
|
defp print_input_types() do
|
2016-05-05 17:26:31 +08:00
|
|
|
Helpers.commands
|
|
|
|
|
|> Map.values
|
|
|
|
|
|> Enum.filter_map(
|
|
|
|
|
&:erlang.function_exported(&1, :usage_additional, 0),
|
|
|
|
|
&(&1.usage_additional))
|
|
|
|
|
|> Enum.join("\n\n")
|
|
|
|
|
|> IO.puts
|
2016-03-05 01:42:43 +08:00
|
|
|
end
|
2016-05-05 03:37:35 +08:00
|
|
|
|
2016-05-24 19:33:11 +08:00
|
|
|
def banner(_,_), do: nil
|
2016-05-05 03:37:35 +08:00
|
|
|
def flags, do: @flags
|
2016-03-05 01:42:43 +08:00
|
|
|
end
|