Get path from config in mix task
This commit is contained in:
parent
95b04823ce
commit
ef76548337
@ -1,6 +1,8 @@
|
|||||||
defmodule Mix.Tasks.Pandoc do
|
defmodule Mix.Tasks.Pandoc do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
|
||||||
|
@ext ".md"
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def run(args) do
|
def run(args) do
|
||||||
switches = [runtime_config: :boolean]
|
switches = [runtime_config: :boolean]
|
||||||
@ -17,15 +19,17 @@ defmodule Mix.Tasks.Pandoc do
|
|||||||
install_and_run(remaining_args)
|
install_and_run(remaining_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp install_and_run([profile | args] = _all) do
|
defp install_and_run([profile | _args] = all) do
|
||||||
IO.puts("mix task args #{inspect(args)}")
|
IO.puts("Converting markdown...")
|
||||||
|
|
||||||
"documents"
|
profile = String.to_atom(profile)
|
||||||
|> File.ls!()
|
config = Application.get_env(:pandoc, profile)
|
||||||
|
|
||||||
|
(config[:cd] || File.cwd!())
|
||||||
|
|> Path.join("*#{@ext}")
|
||||||
|
|> Path.wildcard()
|
||||||
|> Enum.each(fn path ->
|
|> Enum.each(fn path ->
|
||||||
all = [profile, path]
|
case Pandoc.run(profile, Path.basename(path)) do
|
||||||
|
|
||||||
case Pandoc.run(String.to_atom(profile), [path]) do
|
|
||||||
0 -> :ok
|
0 -> :ok
|
||||||
status -> Mix.raise("`mix pandoc #{Enum.join(all, " ")}` exited with #{status}")
|
status -> Mix.raise("`mix pandoc #{Enum.join(all, " ")}` exited with #{status}")
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ defmodule Pandoc do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(profile, extra_args) do
|
def run(profile, path) do
|
||||||
config = Application.get_env(:pandoc, profile)
|
config = Application.get_env(:pandoc, profile)
|
||||||
args = config[:args] || []
|
args = config[:args] || []
|
||||||
|
|
||||||
@ -33,8 +33,6 @@ defmodule Pandoc do
|
|||||||
stderr_to_stdout: true
|
stderr_to_stdout: true
|
||||||
]
|
]
|
||||||
|
|
||||||
[path] = extra_args
|
|
||||||
|
|
||||||
args =
|
args =
|
||||||
List.update_at(args, -1, fn v ->
|
List.update_at(args, -1, fn v ->
|
||||||
Path.join(
|
Path.join(
|
||||||
@ -46,6 +44,6 @@ defmodule Pandoc do
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
"pandoc" |> System.cmd(args ++ extra_args, opts) |> elem(1)
|
"pandoc" |> System.cmd(args ++ [path], opts) |> elem(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ defmodule Pandoc.Watcher do
|
|||||||
|
|
||||||
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
|
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
|
||||||
case {Path.extname(path), :closed in events} do
|
case {Path.extname(path), :closed in events} do
|
||||||
{@ext, true} -> Pandoc.run(state[:profile], [path])
|
{@ext, true} -> Pandoc.run(state[:profile], path)
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
5
mix.exs
5
mix.exs
@ -8,7 +8,7 @@ defmodule Pandoc.MixProject do
|
|||||||
elixir: "~> 1.14",
|
elixir: "~> 1.14",
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
description: "Pandoc",
|
description: "Pandoc",
|
||||||
package: []
|
package: [links: [], licenses: ["MIT"]]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -23,7 +23,8 @@ defmodule Pandoc.MixProject do
|
|||||||
# Run "mix help deps" to learn about dependencies.
|
# Run "mix help deps" to learn about dependencies.
|
||||||
defp deps do
|
defp deps do
|
||||||
[
|
[
|
||||||
{:file_system, "~> 1.0"}
|
{:file_system, "~> 1.0"},
|
||||||
|
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
9
mix.lock
Normal file
9
mix.lock
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
%{
|
||||||
|
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
|
||||||
|
"ex_doc": {:hex, :ex_doc, "0.35.1", "de804c590d3df2d9d5b8aec77d758b00c814b356119b3d4455e4b8a8687aecaf", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2121c6402c8d44b05622677b761371a759143b958c6c19f6558ff64d0aed40df"},
|
||||||
|
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
|
||||||
|
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
|
||||||
|
"makeup_elixir": {:hex, :makeup_elixir, "1.0.0", "74bb8348c9b3a51d5c589bf5aebb0466a84b33274150e3b6ece1da45584afc82", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "49159b7d7d999e836bedaf09dcf35ca18b312230cf901b725a64f3f42e407983"},
|
||||||
|
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
|
||||||
|
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user