~ihabunek/triglav

ref: f8f7b939d718089aa8ab1b9939d768fd7cf3a2ec triglav/lib/mix/tasks/triglav/osmosis_load.ex -rw-r--r-- 682 bytes
f8f7b939Ivan Habunek Fix flag for starting only repo 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
defmodule Mix.Tasks.Triglav.OsmosisLoad do
  use Mix.Task

  alias Triglav.Import.Osmosis

  @shortdoc "(re)Creates the Osmosis schema and loads a given pbf file"

  @impl Mix.Task
  def run([pbf_path]) do
    Application.put_env(:triglav, :repo_only, true)
    {:ok, _} = Application.ensure_all_started(:triglav)

    if not Osmosis.schema_exists?() or confirm() do
      Osmosis.create_schema()
      Osmosis.load_file(pbf_path)
    else
      IO.puts("Aborted")
    end
  end

  defp confirm() do
    response =
      IO.gets("\nOsmosis schema already exists. This will overwrite it. Are you sure? [y/N]: ")
      |> String.trim()

    String.downcase(response) == "y"
  end
end