Skip to content

Commit

Permalink
fix: properly parse csv/keep options
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 14, 2024
1 parent f15e761 commit bfc3d30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/igniter/util/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,22 @@ defmodule Igniter.Util.Info do
OptionParser.parse!(
argv,
[
{options_key, merged_schema.schema || []},
{options_key, clean_csv(merged_schema.schema || [])},
{:aliases, merged_schema.aliases || []}
]
)
end

defp clean_csv(schema) do
Enum.map(schema, fn
{k, :csv} ->
{k, :keep}

{k, v} ->
{k, v}
end)
end

@doc false
def args_for_group(argv, group) do
case argv do
Expand Down
9 changes: 7 additions & 2 deletions lib/mix/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ defmodule Igniter.Mix.Task do
{k, v}
end)

{parsed, _} = OptionParser.parse!(argv, switches: info.schema, aliases: info.aliases)
{parsed, _} = OptionParser.parse!(argv, switches: schema, aliases: info.aliases)

parsed =
info.schema
Expand Down Expand Up @@ -132,9 +132,12 @@ defmodule Igniter.Mix.Task do
end)

:error ->
parsed
Keyword.put(parsed, k, [])
end

{k, :keep}, parsed ->
Keyword.put_new(parsed, k, [])

_, parsed ->
parsed
end)
Expand All @@ -146,6 +149,8 @@ defmodule Igniter.Mix.Task do
Mix.shell().error(
"Missing required flag #{String.replace(to_string(option), "_", "-")} "
)

exit({:shutdown, 1})
end
end)

Expand Down

0 comments on commit bfc3d30

Please sign in to comment.