Current section
Files
Jump to
Current section
Files
lib/mix/tasks/down.ex
defmodule Mix.Tasks.Eise.Down do
@moduledoc """
Handles all uninstallations
"""
use Mix.Task
import Eisegesis.Executor
alias Eisegesis.Output
alias Eisegesis.Passenger.{Asdf, Dotfiles, Homebrew, Repos, Yarn}
def run(args \\ []) do
start_section("GOODBYE FROM EISEGESIS!")
args
|> parse_args()
|> get_path_for()
|> Toml.decode_file()
|> parse_toml()
|> Enum.filter(fn {k, _} -> k != "shell" end)
|> Task.async_stream(&each_module/1)
|> Enum.into([])
end
defp parse_args(args) do
{[{_, dir}], _, invalids} = OptionParser.parse(args, strict: [setup_path: :string])
if length(invalids) > 0 do
Output.error(
"ERROR",
"Ok, these arguments are invalid... You aren't helping me... Look at this:"
)
IO.inspect(invalids)
Output.red("That isn't even makes sense... Run with `--help` flag")
|> IO.puts()
System.halt(1)
end
dir
end
defp each_module({"asdf" = passenger, opts}), do: Asdf.down(passenger, opts)
defp each_module({"yarn" = passenger, opts}), do: Yarn.down(passenger, opts)
defp each_module({"homebrew" = passenger, opts}), do: Homebrew.down(passenger, opts)
defp each_module({"dotfiles" = passenger, opts}), do: Dotfiles.down(passenger, opts)
defp each_module({"repos" = passenger, opts}), do: Repos.down(passenger, opts)
defp each_module(_),
do: Output.error("There's a error on your `setup.toml` file", "unable to parse `setup.toml`")
defp parse_toml({:ok, content}), do: content
defp parse_toml({:error, error}) do
Output.error(
"Error while trying to initialize `eisegesis`\nRecheck your `setup.toml` file",
error
)
System.halt(1)
end
end