Make it possible to get command help by typing 'rabbitmqctl mycommand --help'
Add a new default switch `help` Add an alias `?` Make rabbitmqctl display command help if this option is true for known commands.
This commit is contained in:
parent
91bb84bc82
commit
5e5f4d461c
|
|
@ -218,7 +218,8 @@ defmodule RabbitMQ.CLI.Core.Parser do
|
|||
plugins_dir: :string,
|
||||
enabled_plugins_file: :string,
|
||||
aliases_file: :string,
|
||||
erlang_cookie: :atom
|
||||
erlang_cookie: :atom,
|
||||
help: :boolean
|
||||
]
|
||||
end
|
||||
|
||||
|
|
@ -231,7 +232,8 @@ defmodule RabbitMQ.CLI.Core.Parser do
|
|||
l: :longnames,
|
||||
# for backwards compatibility,
|
||||
# not all commands support timeouts
|
||||
t: :timeout
|
||||
t: :timeout,
|
||||
"?": :help
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.HelpCommand do
|
|||
all_usage(opts)
|
||||
|
||||
command ->
|
||||
Enum.join(
|
||||
[base_usage(command, opts)] ++
|
||||
options_usage() ++
|
||||
additional_usage(command),
|
||||
"\n\n"
|
||||
)
|
||||
all_usage(command, opts)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -72,6 +67,13 @@ defmodule RabbitMQ.CLI.Ctl.Commands.HelpCommand do
|
|||
)
|
||||
end
|
||||
|
||||
def all_usage(command, opts) do
|
||||
Enum.join([base_usage(command, opts)] ++
|
||||
options_usage() ++
|
||||
additional_usage(command),
|
||||
"\n\n")
|
||||
end
|
||||
|
||||
def usage(), do: "help (<command> | [--list-commands])"
|
||||
|
||||
defp tool_usage(tool_name) do
|
||||
|
|
|
|||
|
|
@ -80,38 +80,44 @@ defmodule RabbitMQCtl do
|
|||
|
||||
_ ->
|
||||
options = parsed_options |> merge_all_defaults |> normalise_options
|
||||
{arguments, options} = command.merge_defaults(arguments, options)
|
||||
|
||||
maybe_with_distribution(command, options, fn ->
|
||||
# rabbitmq/rabbitmq-cli#278
|
||||
options = Helpers.normalise_node_option(options)
|
||||
case options[:help] do
|
||||
true ->
|
||||
{:error, ExitCodes.exit_ok(), HelpCommand.all_usage(command, options)};
|
||||
_ ->
|
||||
{arguments, options} = command.merge_defaults(arguments, options)
|
||||
|
||||
# The code below implements a tiny decision tree that has
|
||||
# to do with CLI argument and environment state validation.
|
||||
maybe_with_distribution(command, options, fn ->
|
||||
# rabbitmq/rabbitmq-cli#278
|
||||
options = Helpers.normalise_node_option(options)
|
||||
|
||||
# validate CLI arguments
|
||||
case command.validate(arguments, options) do
|
||||
:ok ->
|
||||
# then optionally validate execution environment
|
||||
case maybe_validate_execution_environment(command, arguments, options) do
|
||||
# The code below implements a tiny decision tree that has
|
||||
# to do with CLI argument and environment state validation.
|
||||
|
||||
# validate CLI arguments
|
||||
case command.validate(arguments, options) do
|
||||
:ok ->
|
||||
result = proceed_to_execution(command, arguments, options)
|
||||
handle_command_output(result, command, options, output_fun)
|
||||
# then optionally validate execution environment
|
||||
case maybe_validate_execution_environment(command, arguments, options) do
|
||||
:ok ->
|
||||
result = proceed_to_execution(command, arguments, options)
|
||||
handle_command_output(result, command, options, output_fun)
|
||||
|
||||
{:validation_failure, err} ->
|
||||
environment_validation_error_output(err, command, unparsed_command, options)
|
||||
|
||||
{:error, _} = err ->
|
||||
format_error(err, options, command)
|
||||
end
|
||||
|
||||
{:validation_failure, err} ->
|
||||
environment_validation_error_output(err, command, unparsed_command, options)
|
||||
argument_validation_error_output(err, command, unparsed_command, options)
|
||||
|
||||
{:error, _} = err ->
|
||||
format_error(err, options, command)
|
||||
end
|
||||
|
||||
{:validation_failure, err} ->
|
||||
argument_validation_error_output(err, command, unparsed_command, options)
|
||||
|
||||
{:error, _} = err ->
|
||||
format_error(err, options, command)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ defmodule RabbitMQCtlTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
## ------------------------ --help option -------------------------------------
|
||||
|
||||
test "--help option prints help for command and exits normally" do
|
||||
command = ["status", "--help"]
|
||||
assert capture_io(fn ->
|
||||
error_check(command, exit_ok())
|
||||
end) =~ ~r/Usage:/
|
||||
end
|
||||
|
||||
## ------------------------ Error Messages ------------------------------------
|
||||
test "print error message on a bad connection" do
|
||||
command = ["status", "-n", "sandwich@pastrami"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue