Spec fixes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-10-05 17:43:45 +02:00
parent 76bc409f68
commit dee7c58449
33 changed files with 193 additions and 234 deletions

View File

@@ -71,10 +71,7 @@ defmodule Mix.Tasks.Mobilizon.Actors.Refresh do
Actor #{preferred_username} refreshed
""")
{:error, err} when is_binary(err) ->
shell_error(err)
_err ->
{:error, _err} ->
shell_error("Error while refreshing actor #{preferred_username}")
end
end

View File

@@ -187,35 +187,29 @@ defmodule Mix.Tasks.Mobilizon.Instance do
end
end
@spec write_config(String.t(), String.t()) :: :ok | {:error, atom()}
defp write_config(config_path, result_config) do
shell_info("Writing config to #{config_path}.")
case File.write(config_path, result_config) do
:ok ->
:ok
with {:error, err} <- File.write(config_path, result_config) do
shell_error(
"\nERROR: Unable to write config file to #{config_path}. Make sure you have permissions on the destination and that the parent path exists.\n"
)
{:error, err} ->
shell_error(
"\nERROR: Unable to write config file to #{config_path}. Make sure you have permissions on the destination and that the parent path exists.\n"
)
{:error, err}
{:error, err}
end
end
@spec write_psql(String.t(), String.t()) :: :ok | {:error, atom()}
defp write_psql(psql_path, result_psql) do
shell_info("Writing #{psql_path}.")
case File.write(psql_path, result_psql) do
:ok ->
:ok
with {:error, err} <- File.write(psql_path, result_psql) do
shell_error(
"\nERROR: Unable to write psql file to #{psql_path}. Make sure you have permissions on the destination and that the parent path exists.\n"
)
{:error, err} ->
shell_error(
"\nERROR: Unable to write psql file to #{psql_path}. Make sure you have permissions on the destination and that the parent path exists.\n"
)
{:error, err}
{:error, err}
end
end
end

View File

@@ -34,22 +34,16 @@ defmodule Mix.Tasks.Mobilizon.Media.CleanOrphan do
start_mobilizon()
case CleanOrphanMedia.clean(dry_run: dry_run, grace_period: grace_period) do
{:ok, medias} ->
if length(medias) > 0 do
if dry_run or verbose do
details(medias, dry_run, verbose)
end
{:ok, medias} = CleanOrphanMedia.clean(dry_run: dry_run, grace_period: grace_period)
result(dry_run, length(medias))
else
empty_result(dry_run)
end
if length(medias) > 0 do
if dry_run or verbose do
details(medias, dry_run, verbose)
end
:ok
_err ->
shell_error("Error while cleaning orphan media files")
result(dry_run, length(medias))
else
empty_result(dry_run)
end
end
@@ -70,7 +64,7 @@ defmodule Mix.Tasks.Mobilizon.Media.CleanOrphan do
end)
end
@spec result(boolean(), boolean()) :: :ok
@spec result(boolean(), non_neg_integer()) :: :ok
defp result(dry_run, nb_medias) do
if dry_run do
shell_info("#{nb_medias} files would have been deleted")

View File

@@ -13,7 +13,7 @@ defmodule Mix.Tasks.Mobilizon.Relay.Accept do
start_mobilizon()
case Relay.accept(target) do
{:ok, _activity} ->
{:ok, _activity, _follow} ->
# put this task to sleep to allow the genserver to push out the messages
:timer.sleep(500)

View File

@@ -35,23 +35,20 @@ defmodule Mix.Tasks.Mobilizon.Users.Clean do
start_mobilizon()
case CleanUnconfirmedUsers.clean(dry_run: dry_run, grace_period: grace_period) do
{:ok, deleted_users} ->
if length(deleted_users) > 0 do
if dry_run or verbose do
details(deleted_users, dry_run, verbose)
end
{:ok, deleted_users} =
CleanUnconfirmedUsers.clean(dry_run: dry_run, grace_period: grace_period)
result(dry_run, length(deleted_users))
else
empty_result(dry_run)
end
if length(deleted_users) > 0 do
if dry_run or verbose do
details(deleted_users, dry_run, verbose)
end
:ok
_err ->
shell_error("Error while cleaning unconfirmed users")
result(dry_run, length(deleted_users))
else
empty_result(dry_run)
end
:ok
end
@spec details(list(Media.t()), boolean(), boolean()) :: :ok