ctl add_vhost: make it possible to provide a description
This commit is contained in:
parent
5e04dd41ab
commit
2c6f5a1146
|
|
@ -18,21 +18,32 @@ defmodule RabbitMQ.CLI.Ctl.Commands.AddVhostCommand do
|
|||
|
||||
@behaviour RabbitMQ.CLI.CommandBehaviour
|
||||
|
||||
use RabbitMQ.CLI.Core.MergesNoDefaults
|
||||
def switches(), do: [description: :string,
|
||||
tags: :string]
|
||||
def aliases(), do: [d: :description]
|
||||
|
||||
def merge_defaults(args, opts) do
|
||||
{args, Map.merge(%{description: "", tags: ""}, opts)}
|
||||
end
|
||||
use RabbitMQ.CLI.Core.AcceptsOnePositionalArgument
|
||||
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
|
||||
|
||||
def run([vhost], %{node: node_name, description: desc, tags: tags}) do
|
||||
:rabbit_misc.rpc_call(node_name, :rabbit_vhost, :add, [vhost, desc, tags, Helpers.cli_acting_user()])
|
||||
end
|
||||
def run([vhost], %{node: node_name}) do
|
||||
:rabbit_misc.rpc_call(node_name, :rabbit_vhost, :add, [vhost, Helpers.cli_acting_user()])
|
||||
end
|
||||
|
||||
use RabbitMQ.CLI.DefaultOutput
|
||||
|
||||
def usage, do: "add_vhost <vhost>"
|
||||
def usage, do: "add_vhost <vhost> [--description <description> --tags \"<tag1> <tag2> <...>\"]"
|
||||
|
||||
def usage_additional() do
|
||||
[
|
||||
["<vhost>", "Virtual host name"]
|
||||
["<vhost>", "Virtual host name"],
|
||||
["--description <descriptioon>", "Virtual host description"],
|
||||
["--tags <tags>", "Space separated list of tags"]
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,20 @@ defmodule AddVhostCommandTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "validate: wrong number of arguments results in arg count errors" do
|
||||
test "validate: no arguments fails validation" do
|
||||
assert @command.validate([], %{}) == {:validation_failure, :not_enough_args}
|
||||
end
|
||||
|
||||
test "validate: too many arguments fails validation" do
|
||||
assert @command.validate(["test", "extra"], %{}) == {:validation_failure, :too_many_args}
|
||||
end
|
||||
|
||||
test "validate: one argument passes validation" do
|
||||
assert @command.validate(["new-vhost"], %{}) == :ok
|
||||
assert @command.validate(["new-vhost"], %{description: "Used by team A"}) == :ok
|
||||
assert @command.validate(["new-vhost"], %{description: "Used by team A for QA purposes", tags: "qa team-a"}) == :ok
|
||||
end
|
||||
|
||||
@tag vhost: @vhost
|
||||
test "run: passing a valid vhost name to a running RabbitMQ node succeeds", context do
|
||||
assert @command.run([context[:vhost]], context[:opts]) == :ok
|
||||
|
|
|
|||
Loading…
Reference in New Issue