~sgiath/aoc-2018

c3384bdbc6f41dabc2454eb62d5d62052647e672 — Sgiath 2 years ago 7c1413d
Improve advent task
1 files changed, 30 insertions(+), 7 deletions(-)

M lib/mix/tasks/advent.ex
M lib/mix/tasks/advent.ex => lib/mix/tasks/advent.ex +30 -7
@@ 1,17 1,40 @@
defmodule Mix.Tasks.Advent do
  use Mix.Task

  alias AdventOfCode.Day01

  @day01_input "lib/day01/input.txt"

  @shortdoc "Run Advent task"
  def run(args) do
    case args do
      ["--help"] ->
        IO.puts("""
          You can run this task to execute my solution for the Advent of Code.

          Eg. for day 1, task 2 run:

              $ mix advent 01 2

          Or you can run it like this:

              $ mix advent --day=01 --part=2

          or like this:

              $ mix advent -d 01 -p 2
        """)

      ["--day=" <> day, "--part=" <> part] ->
        execute(day, part)

      [day, part] ->
        :"Elixir.AdventOfCode.Day#{day}"
        |> apply(:"part#{part}", [File.stream!("lib/day#{day}/input.txt")])
        |> IO.inspect(label: "Day#{day}.part#{part}/1 result")
        execute(day, part)

      ["-d", day, "-p", part] ->
        execute(day, part)
    end
  end

  defp execute(day, part) do
    :"Elixir.AdventOfCode.Day#{day}"
    |> apply(:"part#{part}", [File.stream!("lib/day#{day}/input.txt")])
    |> IO.inspect(label: "Day#{day}.part#{part}/0 result")
  end
end