Skip to content
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .github/workflows/test-mixed-versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ jobs:
matrix:
include:
- erlang_version: "24"
<<<<<<< HEAD
elixir_version: 1.12.3
=======
elixir_version: 1.13.4
#! - erlang_version: "25"
#! elixir_version: 1.13.4
>>>>>>> 3e7d067207 (Bump elixir version in actions)
timeout-minutes: 60
steps:
- name: CHECKOUT REPOSITORY
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ jobs:
matrix:
include:
- erlang_version: "24"
<<<<<<< HEAD
elixir_version: 1.12.3
=======
elixir_version: 1.13.4
#! - erlang_version: "25"
#! elixir_version: 1.13.4
>>>>>>> 3e7d067207 (Bump elixir version in actions)
timeout-minutes: 60
steps:
- name: CHECKOUT REPOSITORY
Expand Down
17 changes: 16 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The process is fairly standard:
* Fork the repository or repositories you plan on contributing to
* Run `make`
* Create a branch with a descriptive name in the relevant repositories
* Make your changes, run tests, commit with a [descriptive message](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), push to your fork
* Make your changes, run tests, ensure correct code formatting, commit with a [descriptive message](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), push to your fork
* Submit pull requests with an explanation what has been changed and **why**
* Submit a filled out and signed [Contributor Agreement](https://github.com/rabbitmq/ca#how-to-submit) if needed (see below)
* Be patient. We will get to your pull request eventually
Expand Down Expand Up @@ -43,6 +43,21 @@ make ct-cluster_rename t=cluster_size_3:partial_one_by_one

Test output is in the `logs/` subdirectory.

## Formatting the RabbitMQ CLI

The RabbitMQ CLI uses the standard [Elixir code formatter](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html). To ensure correct code formatting of the CLI:

```
cd deps/rabbitmq_cli
mix format
```

Running `make` will validate the CLI formatting and issue any necessary warnings. Alternatively, run the format checker in the `deps/rabbitmq_cli` directory:

```
mix format --check-formatted
```

## Code of Conduct

See [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md).
Expand Down
3 changes: 3 additions & 0 deletions deps/rabbitmq_cli/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
5 changes: 2 additions & 3 deletions deps/rabbitmq_cli/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
##
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.


# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand All @@ -25,7 +24,7 @@ use Mix.Config
#
# Or configure a 3rd-party app:
#
config :logger, [level: :warn, console: [device: :standard_error]]
config :logger, level: :warn, console: [device: :standard_error]
#

# It is also possible to import configuration files, relative to this
Expand Down
2 changes: 2 additions & 0 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/auto_complete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule RabbitMQ.CLI.AutoComplete do
def suggest_command(_cmd_name, empty) when empty == %{} do
nil
end

def suggest_command(typed, module_map) do
suggestion =
module_map
Expand All @@ -40,6 +41,7 @@ defmodule RabbitMQ.CLI.AutoComplete do
case suggestion do
{cmd, distance} when distance >= @jaro_distance_limit ->
{:suggest, cmd}

_ ->
nil
end
Expand Down
138 changes: 94 additions & 44 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/command_behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ defmodule RabbitMQ.CLI.CommandBehaviour do
@callback scopes() :: [atom()] | nil
@callback description() :: String.t()
@callback help_section() :: String.t()
@callback usage_additional() :: String.t() | [String.t()] | nonempty_list(pair_of_strings()) | [{String.t(), String.t()}]
@callback usage_additional() ::
String.t()
| [String.t()]
| nonempty_list(pair_of_strings())
| [{String.t(), String.t()}]
@callback usage_doc_guides() :: String.t() | [String.t()]
## Erlang distribution control
## :cli - default rabbitmqctl generated node name
Expand All @@ -57,46 +61,93 @@ defmodule RabbitMQ.CLI.CommandBehaviour do
@callback distribution(map()) :: :cli | :none | {:fun, (map() -> :ok | {:error, any()})}

defmacro defcmd(map) do
usage_q = case map[:usage] do
nil -> :ok
usage ->
quote do def usage(), do: unquote(usage) end
end
scopes_q = case map[:scopes] do
nil -> :ok
scopes ->
quote do def scopes(), do: unquote(scopes) end
end
description_q = case map[:description] do
nil -> :ok
description ->
quote do def description(), do: unquote(description) end
end
help_section_q = case map[:help_section] do
nil -> :ok
help_section ->
quote do def help_section(), do: unquote(help_section) end
end
usage_additional_q = case map[:usage_additional] do
nil -> :ok
usage_additional ->
quote do def usage_additional(), do: unquote(usage_additional) end
end
formatter_q = case map[:formatter] do
nil -> :ok
formatter ->
quote do def formatter(), do: unquote(formatter) end
end
switches_q = case map[:switches] do
nil -> :ok
switches ->
quote do def switches(), do: unquote(switches) end
end
aliases_q = case map[:aliases] do
nil -> :ok
aliases ->
quote do def aliases(), do: unquote(aliases) end
end
usage_q =
case map[:usage] do
nil ->
:ok

usage ->
quote do
def usage(), do: unquote(usage)
end
end

scopes_q =
case map[:scopes] do
nil ->
:ok

scopes ->
quote do
def scopes(), do: unquote(scopes)
end
end

description_q =
case map[:description] do
nil ->
:ok

description ->
quote do
def description(), do: unquote(description)
end
end

help_section_q =
case map[:help_section] do
nil ->
:ok

help_section ->
quote do
def help_section(), do: unquote(help_section)
end
end

usage_additional_q =
case map[:usage_additional] do
nil ->
:ok

usage_additional ->
quote do
def usage_additional(), do: unquote(usage_additional)
end
end

formatter_q =
case map[:formatter] do
nil ->
:ok

formatter ->
quote do
def formatter(), do: unquote(formatter)
end
end

switches_q =
case map[:switches] do
nil ->
:ok

switches ->
quote do
def switches(), do: unquote(switches)
end
end

aliases_q =
case map[:aliases] do
nil ->
:ok

aliases ->
quote do
def aliases(), do: unquote(aliases)
end
end

quote do
unquote(usage_q)
Expand Down Expand Up @@ -129,6 +180,7 @@ defmodule RabbitMQ.CLI.CommandBehaviour do
:rabbitmqctl -> :other
plugin -> {:plugin, plugin}
end

section ->
section
end
Expand Down Expand Up @@ -159,9 +211,7 @@ defmodule RabbitMQ.CLI.CommandBehaviour do
end

def validate_execution_environment(cmd, args, options) do
Helpers.apply_if_exported(cmd,
:validate_execution_environment, [args, options],
:ok)
Helpers.apply_if_exported(cmd, :validate_execution_environment, [args, options], :ok)
end

def distribution(cmd, options) do
Expand Down
5 changes: 5 additions & 0 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/core/alarms.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,35 @@ defmodule RabbitMQ.CLI.Core.Alarms do
def alarm_type(val) when is_atom(val) do
val
end

def alarm_type({:resource_limit, val, _node}) do
val
end

def alarm_type({{:resource_limit, val, _node}, []}) do
val
end

def alarm_maps(xs) do
Enum.map(xs, &alarm_map/1)
end

def alarm_map(:file_descriptor_limit) do
%{
type: :resource_limit,
resource: :file_descriptors,
node: node()
}
end

def alarm_map({{:resource_limit, resource, node}, _}) do
%{
type: :resource_limit,
resource: resource,
node: node
}
end

def alarm_map({:resource_limit, resource, node}) do
%{
type: :resource_limit,
Expand Down
1 change: 1 addition & 0 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/core/command_modules.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ defmodule RabbitMQ.CLI.Core.CommandModules do
|> to_snake_case
|> String.to_atom()
|> List.wrap()

scopes ->
scopes
end
Expand Down
1 change: 0 additions & 1 deletion deps/rabbitmq_cli/lib/rabbitmq/cli/core/feature_flags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
## Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved.

defmodule RabbitMQ.CLI.Core.FeatureFlags do

#
# API
#
Expand Down
21 changes: 13 additions & 8 deletions deps/rabbitmq_cli/lib/rabbitmq/cli/core/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ defmodule RabbitMQ.CLI.Core.Helpers do
def normalise_node(name, node_name_type) do
case NodeName.create(name, node_name_type) do
{:ok, node_name} -> node_name
other -> other
other -> other
end
end

# rabbitmq/rabbitmq-cli#278
def normalise_node_option(options) do
node_opt = Config.get_option(:node, options)
longnames_opt = Config.get_option(:longnames, options)

case NodeName.create(node_opt, longnames_opt) do
{:error, _} = err ->
err

{:ok, val} ->
{:ok, Map.put(options, :node, val)}
end
Expand All @@ -38,10 +40,12 @@ defmodule RabbitMQ.CLI.Core.Helpers do
def normalise_node_option(nil, _, _) do
nil
end

def normalise_node_option(node_opt, longnames_opt, options) do
case NodeName.create(node_opt, longnames_opt) do
{:error, _} = err ->
err

{:ok, val} ->
{:ok, Map.put(options, :node, val)}
end
Expand All @@ -50,6 +54,7 @@ defmodule RabbitMQ.CLI.Core.Helpers do
def case_insensitive_format(%{format: format} = opts) do
%{opts | format: String.downcase(format)}
end

def case_insensitive_format(opts), do: opts

def nodes_in_cluster(node, timeout \\ :infinity) do
Expand Down Expand Up @@ -116,17 +121,17 @@ defmodule RabbitMQ.CLI.Core.Helpers do
end

def atomize_values(map, keys) do
Enum.reduce(map, %{},
fn({k, v}, acc) ->
case Enum.member?(keys, k) do
false -> Map.put(acc, k, v)
true -> Map.put(acc, k, DataCoercion.to_atom(v))
end
end)
Enum.reduce(map, %{}, fn {k, v}, acc ->
case Enum.member?(keys, k) do
false -> Map.put(acc, k, v)
true -> Map.put(acc, k, DataCoercion.to_atom(v))
end
end)
end

def apply_if_exported(mod, fun, args, default) do
Code.ensure_loaded(mod)

case function_exported?(mod, fun, length(args)) do
true -> apply(mod, fun, args)
false -> default
Expand Down
Loading