debianize-mobilizon/lib/mobilizon/cli.ex
Thomas Citharel b5d9b82bdd
Refactor Mobilizon.Federation.ActivityPub and add typespecs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-09-29 16:31:11 +02:00

57 lines
1.2 KiB
Elixir

# Portions of this file are derived from Pleroma:
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mobilizon.CLI do
@moduledoc """
CLI wrapper for releases
"""
alias Mix.Tasks.Mobilizon.Ecto.{Migrate, Rollback}
@spec run(String.t()) :: any()
def run(args) do
[task | args] = String.split(args)
case task do
"migrate" -> migrate(args)
"rollback" -> rollback(args)
task -> mix_task(task, args)
end
end
defp mix_task(task, args) do
Application.load(:mobilizon)
{:ok, modules} = :application.get_key(:mobilizon, :modules)
module =
Enum.find(modules, fn module ->
module = Module.split(module)
case module do
["Mix", "Tasks", "Mobilizon" | rest] ->
String.downcase(Enum.join(rest, ".")) == task
_ ->
false
end
end)
if module do
module.run(args)
else
IO.puts("The task #{task} does not exist")
end
end
@spec migrate(String.t()) :: any()
defp migrate(args) do
Migrate.run(args)
end
@spec rollback(String.t()) :: any()
defp rollback(args) do
Rollback.run(args)
end
end