Get path from config in mix task
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
defmodule Mix.Tasks.Pandoc do
|
||||
use Mix.Task
|
||||
|
||||
@ext ".md"
|
||||
|
||||
@impl true
|
||||
def run(args) do
|
||||
switches = [runtime_config: :boolean]
|
||||
@@ -17,15 +19,17 @@ defmodule Mix.Tasks.Pandoc do
|
||||
install_and_run(remaining_args)
|
||||
end
|
||||
|
||||
defp install_and_run([profile | args] = _all) do
|
||||
IO.puts("mix task args #{inspect(args)}")
|
||||
defp install_and_run([profile | _args] = all) do
|
||||
IO.puts("Converting markdown...")
|
||||
|
||||
"documents"
|
||||
|> File.ls!()
|
||||
profile = String.to_atom(profile)
|
||||
config = Application.get_env(:pandoc, profile)
|
||||
|
||||
(config[:cd] || File.cwd!())
|
||||
|> Path.join("*#{@ext}")
|
||||
|> Path.wildcard()
|
||||
|> Enum.each(fn path ->
|
||||
all = [profile, path]
|
||||
|
||||
case Pandoc.run(String.to_atom(profile), [path]) do
|
||||
case Pandoc.run(profile, Path.basename(path)) do
|
||||
0 -> :ok
|
||||
status -> Mix.raise("`mix pandoc #{Enum.join(all, " ")}` exited with #{status}")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user