From 53d2082ad0a3d65a46ee7a6a86d9947b5bde72d1 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 1 Dec 2024 12:32:21 +0000 Subject: [PATCH] Ensure flyctl is installed before running Mix tasks --- lib/mix/tasks/music_library/prod/helpers.ex | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/music_library/prod/helpers.ex b/lib/mix/tasks/music_library/prod/helpers.ex index 0d6baa1b..a6396011 100644 --- a/lib/mix/tasks/music_library/prod/helpers.ex +++ b/lib/mix/tasks/music_library/prod/helpers.ex @@ -1,9 +1,23 @@ defmodule Mix.Tasks.MusicLibrary.Prod.Helpers do def fly_ssh(command) do - System.cmd("flyctl", ["ssh", "console", "--command", command], into: IO.stream()) + if flyctl_installed?() do + System.cmd("flyctl", ["ssh", "console", "--command", command], into: IO.stream()) + else + IO.puts("Please install flyctl first") + System.halt(1) + end end def fly_sftp_get(remote_path, local_path) do - System.cmd("flyctl", ["ssh", "sftp", "get", remote_path, local_path], into: IO.stream()) + if flyctl_installed?() do + System.cmd("flyctl", ["ssh", "sftp", "get", remote_path, local_path], into: IO.stream()) + else + IO.puts("Please install flyctl first") + System.halt(1) + end + end + + defp flyctl_installed?() do + System.find_executable("flyctl") end end