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

104 lines
3.6 KiB
Elixir
Raw Normal View History

## 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/
##
## 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.
alias RabbitMQ.CLI.Formatters.FormatterHelpers
defmodule RabbitMQ.CLI.DefaultOutput do
2016-09-05 18:06:45 +08:00
# When `use RabbitMQ.CLI.DefaultOutput` is invoked,
# this will define output/2 that delegates to RabbitMQ.CLI.DefaultOutput.output/2.
2016-08-22 19:58:37 +08:00
defmacro __using__(_) do
quote do
def output(result, opts) do
RabbitMQ.CLI.DefaultOutput.output(result, opts)
end
2016-08-22 19:58:37 +08:00
end
end
def output(result, opts \\ %{}) do
format_output(normalize_output(result, opts))
2016-08-22 19:58:37 +08:00
end
2016-08-22 19:58:37 +08:00
def mnesia_running_error(node_name) do
"Mnesia is still running on node #{node_name}.\n" <>
2019-01-31 03:20:29 +08:00
"Please stop RabbitMQ with 'rabbitmqctl stop_app' first."
2016-08-22 19:58:37 +08:00
end
defp normalize_output(:ok, %{node: node_name, formatter: "json"}) do
{:ok, %{"result" => "ok", "node" => node_name}}
end
defp normalize_output(:ok, _opts), do: :ok
defp normalize_output({:ok, value}, %{node: node_name, formatter: "json"}) do
{:ok, %{"result" => "ok", "node" => node_name, "value" => value}}
end
defp normalize_output({:ok, _} = input, _opts), do: input
defp normalize_output({:stream, _} = input, _opts), do: input
defp normalize_output({:badrpc_multi, _, _} = input, _opts), do: {:error, input}
defp normalize_output({:badrpc, :nodedown} = input, _opts), do: {:error, input}
defp normalize_output({:badrpc, :timeout} = input, _opts), do: {:error, input}
defp normalize_output({:badrpc, {:timeout, _n}} = input, _opts), do: {:error, input}
defp normalize_output({:badrpc, {:timeout, _n, _msg}} = input, _opts), do: {:error, input}
defp normalize_output({:badrpc, {:EXIT, reason}}, _opts), do: {:error, reason}
defp normalize_output({:error, exit_code, string}, _opts) when is_integer(exit_code) do
{:error, exit_code, to_string(string)}
end
defp normalize_output({:error, format, args}, _opts)
2019-01-31 03:20:29 +08:00
when (is_list(format) or is_binary(format)) and is_list(args) do
{:error, to_string(:rabbit_misc.format(format, args))}
end
defp normalize_output({:error, _} = input, _opts), do: input
defp normalize_output({:error_string, string}, _opts) do
{:error, to_string(string)}
end
defp normalize_output(unknown, _opts) when is_atom(unknown), do: {:error, unknown}
defp normalize_output({unknown, _} = input, _opts) when is_atom(unknown), do: {:error, input}
defp normalize_output(result, _opts) when not is_atom(result), do: {:ok, result}
2016-08-22 19:58:37 +08:00
defp format_output({:error, _} = result) do
result
2016-08-22 19:58:37 +08:00
end
2019-04-09 18:46:32 +08:00
defp format_output({:error, _, _} = result) do
result
end
2019-01-31 03:20:29 +08:00
defp format_output(:ok) do
2016-08-22 19:58:37 +08:00
:ok
end
2019-01-31 03:20:29 +08:00
defp format_output({:ok, output}) do
2016-08-22 19:58:37 +08:00
case Enumerable.impl_for(output) do
nil ->
2019-01-31 03:20:29 +08:00
{:ok, output}
2016-12-07 01:14:59 +08:00
## Do not streamify plain maps
Enumerable.Map ->
2019-01-31 03:20:29 +08:00
{:ok, output}
## Do not streamify proplists
Enumerable.List ->
case FormatterHelpers.proplist?(output) do
2019-01-31 03:20:29 +08:00
true -> {:ok, output}
false -> {:stream, output}
2019-01-31 03:20:29 +08:00
end
_ ->
{:stream, output}
end
end
2019-01-31 03:20:29 +08:00
defp format_output({:stream, stream}) do
2017-04-05 02:23:50 +08:00
{:stream, stream}
end
end