Add Pleroma.Utils.command_available?/1 and use where appropriate

This commit is contained in:
Roman Chvanikov 2020-07-11 15:48:45 +03:00
commit aedbbec88a
4 changed files with 28 additions and 4 deletions

View file

@ -9,4 +9,19 @@ defmodule Pleroma.Utils do
|> Enum.map(&Path.join(dir, &1))
|> Kernel.ParallelCompiler.compile()
end
@doc """
POSIX-compliant check if command is available in the system
## Examples
iex> command_available?("git")
true
iex> command_available?("wrongcmd")
false
"""
@spec command_available?(String.t()) :: boolean()
def command_available?(command) do
match?({_output, 0}, System.cmd("sh", ["-c", "command -v #{command}"]))
end
end