From f7c0b1e3f301e8eed72cadecdd9bf892c529173c Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Fri, 22 Oct 2021 15:47:04 +0200 Subject: [PATCH] Support CLI diagnose options for releases When an Elixir app is made into a release with `mix release` it's more difficult to run the diagnose command. A user needs to eval this command: ``` bin/your_app eval ":appsignal_tasks.diagnose()" ``` It's not possible to pass along `--send-report` this way, because it will be will ignored for some reason. To allow for the options to be available for this method of calling the diagnose command, allow the Mix task (that's being called this way) to receive arguments and pass them to the Diagnose module, like how it would be done if one would call `mix appsignal.diagnose --send-report`. This change is necessary for the diagnose tests (https://github.com/appsignal/diagnose_tests) test suite, because we need to run the diagnose from a released app. If we'd run a unreleased app the AppSignal package would recompile on every run, making it impossible to overwrite the install and download reports for testing. --- .changesets/support-mix-task-diagnose-arguments.md | 13 +++++++++++++ lib/appsignal/utils/tasks.ex | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changesets/support-mix-task-diagnose-arguments.md diff --git a/.changesets/support-mix-task-diagnose-arguments.md b/.changesets/support-mix-task-diagnose-arguments.md new file mode 100644 index 000000000..d84bd5f31 --- /dev/null +++ b/.changesets/support-mix-task-diagnose-arguments.md @@ -0,0 +1,13 @@ +--- +bump: "patch" +--- + +Support mix task diagnose arguments. When an app is released with `mix release` CLI arguments cannot normally be passed to the diagnose task. Use the `eval` command pass along the CLI arguments as function arguments. + +``` +mix format +# Without arguments +bin/your_app eval ':appsignal_tasks.diagnose()' +# With arguments +bin/your_app eval ':appsignal_tasks.diagnose(["--send-report"])' +``` diff --git a/lib/appsignal/utils/tasks.ex b/lib/appsignal/utils/tasks.ex index 4b376699b..826be9995 100644 --- a/lib/appsignal/utils/tasks.ex +++ b/lib/appsignal/utils/tasks.ex @@ -1,7 +1,7 @@ defmodule :appsignal_tasks do @moduledoc false - def diagnose do - Mix.Tasks.Appsignal.Diagnose.run(nil) + def diagnose(args \\ []) do + Mix.Tasks.Appsignal.Diagnose.run(args) :init.stop() end