rabbitmq-server/deps/rabbitmq_cli/lib/rabbitmq/cli/command_behaviour.ex

180 lines
5.7 KiB
Elixir
Raw Normal View History

2016-05-05 05:03:09 +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
URL Cleanup This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener). # HTTP URLs that Could Not Be Fixed These URLs were unable to be fixed. Please review them to see if they can be manually resolved. * http://blog.listincomprehension.com/search/label/procket (200) with 1 occurrences could not be migrated: ([https](https://blog.listincomprehension.com/search/label/procket) result ClosedChannelException). * http://dozzie.jarowit.net/trac/wiki/TOML (200) with 1 occurrences could not be migrated: ([https](https://dozzie.jarowit.net/trac/wiki/TOML) result SSLHandshakeException). * http://dozzie.jarowit.net/trac/wiki/subproc (200) with 1 occurrences could not be migrated: ([https](https://dozzie.jarowit.net/trac/wiki/subproc) result SSLHandshakeException). * http://e2project.org (200) with 1 occurrences could not be migrated: ([https](https://e2project.org) result AnnotatedConnectException). * http://erlang.org/doc/reference_manual/distributed.html (200) with 1 occurrences could not be migrated: ([https](https://erlang.org/doc/reference_manual/distributed.html) result ConnectTimeoutException). * http://nitrogenproject.com/ (200) with 2 occurrences could not be migrated: ([https](https://nitrogenproject.com/) result ConnectTimeoutException). * http://proper.softlab.ntua.gr (200) with 1 occurrences could not be migrated: ([https](https://proper.softlab.ntua.gr) result SSLHandshakeException). * http://yaws.hyber.org (200) with 1 occurrences could not be migrated: ([https](https://yaws.hyber.org) result AnnotatedConnectException). * http://choven.ca (503) with 1 occurrences could not be migrated: ([https](https://choven.ca) result ConnectTimeoutException). # Fixed URLs ## Fixed But Review Recommended These URLs were fixed, but the https status was not OK. However, the https status was the same as the http request or http redirected to an https URL, so they were migrated. Your review is recommended. * http://fixprotocol.org/ (301) with 1 occurrences migrated to: https://fixtrading.org ([https](https://fixprotocol.org/) result SSLHandshakeException). * http://erldb.org (UnknownHostException) with 1 occurrences migrated to: https://erldb.org ([https](https://erldb.org) result UnknownHostException). * http://elixir-lang.org/docs/stable/elixir/OptionParser.html (301) with 1 occurrences migrated to: https://elixir-lang.org/docs/stable/elixir/OptionParser.html ([https](https://elixir-lang.org/docs/stable/elixir/OptionParser.html) result 404). * http://elixir-lang.org/docs/stable/elixir/Stream.html (301) with 1 occurrences migrated to: https://elixir-lang.org/docs/stable/elixir/Stream.html ([https](https://elixir-lang.org/docs/stable/elixir/Stream.html) result 404). ## Fixed Success These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended. * http://cloudi.org/ with 27 occurrences migrated to: https://cloudi.org/ ([https](https://cloudi.org/) result 200). * http://elixir-lang.org with 1 occurrences migrated to: https://elixir-lang.org ([https](https://elixir-lang.org) result 200). * http://elixir-lang.org/ with 2 occurrences migrated to: https://elixir-lang.org/ ([https](https://elixir-lang.org/) result 200). * http://elixir-lang.org/getting-started/typespecs-and-behaviours.html with 1 occurrences migrated to: https://elixir-lang.org/getting-started/typespecs-and-behaviours.html ([https](https://elixir-lang.org/getting-started/typespecs-and-behaviours.html) result 200). * http://elixir-lang.org/install.html with 1 occurrences migrated to: https://elixir-lang.org/install.html ([https](https://elixir-lang.org/install.html) result 200). * http://erlware.org/ with 1 occurrences migrated to: https://erlware.org/ ([https](https://erlware.org/) result 200). * http://inaka.github.io/cowboy-trails/ with 1 occurrences migrated to: https://inaka.github.io/cowboy-trails/ ([https](https://inaka.github.io/cowboy-trails/) result 200). * http://ninenines.eu with 6 occurrences migrated to: https://ninenines.eu ([https](https://ninenines.eu) result 200). * http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html with 1 occurrences migrated to: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html ([https](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) result 200). * http://www.actordb.com/ with 2 occurrences migrated to: https://www.actordb.com/ ([https](https://www.actordb.com/) result 200). * http://www.cs.kent.ac.uk/projects/wrangler/Home.html with 1 occurrences migrated to: https://www.cs.kent.ac.uk/projects/wrangler/Home.html ([https](https://www.cs.kent.ac.uk/projects/wrangler/Home.html) result 200). * http://www.rebar3.org with 1 occurrences migrated to: https://www.rebar3.org ([https](https://www.rebar3.org) result 200). * http://contributor-covenant.org with 1 occurrences migrated to: https://contributor-covenant.org ([https](https://contributor-covenant.org) result 301). * http://contributor-covenant.org/version/1/3/0/ with 1 occurrences migrated to: https://contributor-covenant.org/version/1/3/0/ ([https](https://contributor-covenant.org/version/1/3/0/) result 301). * http://inaka.github.com/apns4erl with 1 occurrences migrated to: https://inaka.github.com/apns4erl ([https](https://inaka.github.com/apns4erl) result 301). * http://inaka.github.com/edis/ with 1 occurrences migrated to: https://inaka.github.com/edis/ ([https](https://inaka.github.com/edis/) result 301). * http://lasp-lang.org/ with 1 occurrences migrated to: https://lasp-lang.org/ ([https](https://lasp-lang.org/) result 301). * http://rabbitmq.com/documentation.html with 1 occurrences migrated to: https://rabbitmq.com/documentation.html ([https](https://rabbitmq.com/documentation.html) result 301). * http://saleyn.github.com/erlexec with 1 occurrences migrated to: https://saleyn.github.com/erlexec ([https](https://saleyn.github.com/erlexec) result 301). * http://www.mozilla.org/MPL/ with 290 occurrences migrated to: https://www.mozilla.org/MPL/ ([https](https://www.mozilla.org/MPL/) result 301). * http://zhongwencool.github.io/observer_cli with 1 occurrences migrated to: https://zhongwencool.github.io/observer_cli ([https](https://zhongwencool.github.io/observer_cli) result 301).
2019-03-20 16:13:07 +08:00
## at https://www.mozilla.org/MPL/
2016-05-05 05:03:09 +08:00
##
## 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.
2020-03-10 22:39:56 +08:00
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
2016-05-05 05:03:09 +08:00
defmodule RabbitMQ.CLI.CommandBehaviour do
alias RabbitMQ.CLI.Core.Helpers
2019-03-26 19:20:17 +08:00
@type pair_of_strings :: nonempty_list(String.t())
2019-01-31 03:20:29 +08:00
@callback usage() :: String.t() | [String.t()]
# validates CLI arguments
2019-01-31 03:20:29 +08:00
@callback validate(list(), map()) :: :ok | {:validation_failure, atom() | {atom(), String.t()}}
@callback merge_defaults(list(), map()) :: {list(), map()}
2019-01-31 03:20:29 +08:00
@callback banner(list(), map()) :: [String.t()] | String.t() | nil
@callback run(list(), map()) :: any
2016-09-05 18:29:11 +08:00
# Coerces run/2 return value into the standard command output form
# that is then formatted, printed and returned as an exit code.
# There is a default implementation for this callback in DefaultOutput module
2019-01-31 03:20:29 +08:00
@callback output(any, map()) ::
:ok
| {:ok, any}
| {:stream, Enum.t()}
| {:error, RabbitMQ.CLI.Core.ExitCodes.exit_code(), [String.t()]}
@optional_callbacks formatter: 0,
printer: 0,
scopes: 0,
usage_additional: 0,
usage_doc_guides: 0,
description: 0,
help_section: 0,
switches: 0,
aliases: 0,
# validates execution environment, e.g. file presence,
# whether RabbitMQ is in an expected state on a node, etc
validate_execution_environment: 2,
distribution: 1
2019-01-31 03:20:29 +08:00
@callback validate_execution_environment(list(), map()) ::
:ok | {:validation_failure, atom() | {atom(), any}}
@callback switches() :: Keyword.t()
@callback aliases() :: Keyword.t()
@callback formatter() :: atom()
@callback printer() :: atom()
@callback scopes() :: [atom()] | nil
@callback description() :: String.t()
@callback help_section() :: String.t()
2019-03-26 19:20:17 +08:00
@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
## :none - disable erlang distribution
## {:fun, fun} - use a custom function to start distribution
2019-01-31 03:20:29 +08:00
@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
quote do
unquote(usage_q)
unquote(scopes_q)
unquote(description_q)
unquote(help_section_q)
unquote(usage_additional_q)
unquote(formatter_q)
unquote(switches_q)
unquote(aliases_q)
end
end
def usage(cmd) do
cmd.usage()
end
def scopes(cmd) do
Helpers.apply_if_exported(cmd, :scopes, [], nil)
end
def description(cmd) do
Helpers.apply_if_exported(cmd, :description, [], "")
end
def help_section(cmd) do
case Helpers.apply_if_exported(cmd, :help_section, [], :other) do
:other ->
case Application.get_application(cmd) do
:rabbitmqctl -> :other
plugin -> {:plugin, plugin}
end
section ->
section
end
end
def usage_additional(cmd) do
Helpers.apply_if_exported(cmd, :usage_additional, [], [])
end
def usage_doc_guides(cmd) do
Helpers.apply_if_exported(cmd, :usage_doc_guides, [], [])
end
def formatter(cmd, default) do
Helpers.apply_if_exported(cmd, :formatter, [], default)
end
def printer(cmd, default) do
Helpers.apply_if_exported(cmd, :printer, [], default)
end
def switches(cmd) do
Helpers.apply_if_exported(cmd, :switches, [], [])
end
def aliases(cmd) do
Helpers.apply_if_exported(cmd, :aliases, [], [])
end
def validate_execution_environment(cmd, args, options) do
Helpers.apply_if_exported(cmd,
:validate_execution_environment, [args, options],
:ok)
end
def distribution(cmd, options) do
Helpers.apply_if_exported(cmd, :distribution, [options], :cli)
end
end