66a8b627fe574ddfaadc942c505658710386f201
[akkoma] / lib / pleroma / release_tasks.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ReleaseTasks do
6 def run(args) do
7 [task | args] = String.split(args)
8
9 case task do
10 "migrate" -> migrate(args)
11 task -> mix_task(task, args)
12 end
13 end
14
15 defp mix_task(task, args) do
16 # Modules are not loaded before application starts
17 Mix.Tasks.Pleroma.Common.start_pleroma()
18 {:ok, modules} = :application.get_key(:pleroma, :modules)
19
20 module =
21 Enum.find(modules, fn module ->
22 module = Module.split(module)
23
24 match?(["Mix", "Tasks", "Pleroma" | _], module) and
25 String.downcase(List.last(module)) == task
26 end)
27
28 if module do
29 module.run(args)
30 else
31 IO.puts("The task #{task} does not exist")
32 end
33 end
34
35 defp migrate(_args) do
36 :noop
37 end
38 end