Skip to content

Commit

Permalink
improvement: properly parse with_args in igniter.new
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 23, 2025
1 parent b9a8de5 commit c94ae97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions installer/lib/mix/tasks/igniter.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ defmodule Mix.Tasks.Igniter.New do
local: :string,
example: :boolean,
with: :string,
with_args: :string,
module: :string,
sup: :boolean,
umbrella: :boolean
],
aliases: [i: :install, l: :local, e: :example, w: :with, wa: :with_args]
aliases: [i: :install, l: :local, e: :example, w: :with]
)

install_with = options[:with] || "new"
Expand Down Expand Up @@ -101,7 +100,7 @@ defmodule Mix.Tasks.Igniter.New do
end

with_args =
[name | OptionParser.split(options[:with_args] || "")]
[name | with_args(argv)]

with_args =
if install_with == "phx.new" do
Expand All @@ -118,14 +117,14 @@ defmodule Mix.Tasks.Igniter.New do
end

with_args =
if with_args[:sup] do
if options[:sup] do
with_args ++ ["--sup"]
else
with_args
end

with_args =
if with_args[:umbrella] do
if options[:umbrella] do
with_args ++ ["--umbrella"]
else
with_args
Expand Down Expand Up @@ -203,7 +202,8 @@ defmodule Mix.Tasks.Igniter.New do
try do
rest_args(argv)
rescue
_ -> []
_ ->
[]
end

Mix.Task.run(
Expand All @@ -216,6 +216,20 @@ defmodule Mix.Tasks.Igniter.New do
:ok
end

defp with_args(argv, acc \\ [])

defp with_args([], acc) do
acc
end

defp with_args(["--with-args", next | rest], acc) do
with_args(rest, acc ++ [next])
end

defp with_args([next | rest], acc) do
with_args(rest, acc)
end

defp extract_positional_args(argv) do
do_extract_positional_args(argv, [], [])
end
Expand Down
2 changes: 1 addition & 1 deletion installer/mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Igniter.New.MixProject do
use Mix.Project

@version "0.5.10"
@version "0.5.11"
@scm_url "https://github.com/ash-project/igniter"

def project do
Expand Down

0 comments on commit c94ae97

Please sign in to comment.