blob: 4da8bf1d9c9a9386ed422dc2ef0e8a64f788c7ec (
plain)
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
29
30
31
32
33
34
35
36
37
38
|
defmodule Mix.Tasks.Pandoc do
use Mix.Task
@impl true
def run(args) do
switches = [runtime_config: :boolean]
{opts, remaining_args} = OptionParser.parse_head!(args, switches: switches)
if opts[:runtime_config] do
Mix.Task.run("app.config")
else
Mix.Task.run("loadpaths")
Application.ensure_all_started(:pandoc)
end
Mix.Task.reenable("pandoc")
install_and_run(remaining_args)
end
defp install_and_run([profile | args] = _all) do
IO.puts("mix task args #{inspect(args)}")
"documents"
|> File.ls!()
|> Enum.each(fn path ->
all = [profile, path]
case Pandoc.run(String.to_atom(profile), [path]) do
0 -> :ok
status -> Mix.raise("`mix pandoc #{Enum.join(all, " ")}` exited with #{status}")
end
end)
end
defp install_and_run([]) do
Mix.raise("`mix pandoc` expects the profile as argument")
end
end
|