Skip to content

Commit

Permalink
improvement: add --yes-to-deps option to mix igniter.install
Browse files Browse the repository at this point in the history
improvement: add `--yes-to-deps` when using `mix igniter.new`
  • Loading branch information
zachdaniel committed Dec 25, 2024
1 parent bce96a5 commit ee11c3a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 36 deletions.
2 changes: 1 addition & 1 deletion installer/lib/mix/tasks/igniter.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ defmodule Mix.Tasks.Igniter.New do
_ -> []
end

Mix.Task.run("igniter.install", install_args ++ rest_args)
Mix.Task.run("igniter.install", install_args ++ rest_args ++ ["--yes-to-deps"])
end

:ok
Expand Down
1 change: 1 addition & 0 deletions installer/lib/private/shared_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Installer.Lib.Private.SharedUtils do
* `--dry-run` - Run the task without making any changes.
* `--yes` - Automatically answer yes to any prompts.
* `--yes-to-deps` - Automatically answer yes to any prompts about installing new deps.
* `--example` - Request that installed packages include initial example code.
"""
end
Expand Down
41 changes: 7 additions & 34 deletions lib/igniter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ defmodule Igniter do
if opts[:force?] ||
(!igniter.assigns[:private][:refused_fetch_dependencies?] &&
has_changes?(igniter, ["mix.exs"])) do
igniter = prompt_on_git_changes(igniter, opts)
source = Rewrite.source!(igniter.rewrite, "mix.exs")

original_quoted = Rewrite.Source.get(source, :quoted, 1)
Expand All @@ -811,8 +810,6 @@ defmodule Igniter do
rewrite = Rewrite.update!(igniter.rewrite, source)

if opts[:force?] || changed?(source) do
display_diff([source], opts)

message =
opts[:message] ||
if opts[:error_on_abort?] do
Expand All @@ -821,7 +818,13 @@ defmodule Igniter do
"These dependencies #{IO.ANSI.yellow()}should#{IO.ANSI.reset()} be installed before continuing. Modify mix.exs and install?"
end

if opts[:yes] || !changed?(source) || Igniter.Util.IO.yes?(message) do
if opts[:yes] || opts[:yes_to_deps] || !changed?(source) ||
Igniter.Util.IO.yes?(
message_with_git_warning(
igniter,
Keyword.put(opts, :message, message <> "\n\n#{diff([source])}")
)
) do
rewrite =
case Rewrite.write(rewrite, "mix.exs", :force) do
{:ok, rewrite} -> rewrite
Expand Down Expand Up @@ -1107,36 +1110,6 @@ defmodule Igniter do
end
end

defp prompt_on_git_changes(igniter, opts) do
if opts[:dry_run] || opts[:yes] || igniter.assigns[:test_mode?] || !has_changes?(igniter) do
igniter
else
if Map.get(igniter.assigns, :prompt_on_git_changes?, true) do
case check_git_status() do
{:dirty, output} ->
if Igniter.Util.IO.yes?("""
#{IO.ANSI.red()} Uncommitted changes detected in the project. #{IO.ANSI.reset()}
Output of `git status -s --porcelain`:
#{output}
Continue? You will be prompted again to accept the above changes.
""") do
Igniter.assign(igniter, :prompt_on_git_changes?, false)
else
exit({:shutdown, 1})
end

_ ->
Igniter.assign(igniter, :prompt_on_git_changes?, false)
end
else
igniter
end
end
end

defp message_with_git_warning(igniter, opts) do
message = opts[:message] || "Proceed with changes?"

Expand Down
1 change: 1 addition & 0 deletions lib/igniter/util/install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ defmodule Igniter.Util.Install do
},
"igniter.install",
yes: "--yes" in argv,
yes_to_deps: "--yes-to-deps" in argv,
only: only,
append?: Keyword.get(opts, :append?, false)
)
Expand Down
1 change: 1 addition & 0 deletions lib/mix/task/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ defmodule Igniter.Mix.Task.Info do
switches: [
dry_run: :boolean,
yes: :boolean,
yes_to_deps: :boolean,
only: :keep,
check: :boolean
],
Expand Down
4 changes: 3 additions & 1 deletion lib/mix/tasks/igniter.upgrade.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ defmodule Mix.Tasks.Igniter.Upgrade do
],
schema: [
yes: :boolean,
yes_to_deps: :boolean,
all: :boolean,
only: :string,
target: :string,
no_archives_check: :boolean,
git_ci: :boolean
],
aliases: [y: :yes, a: :all, o: :only, t: :target, n: :no_archives_check, g: :git_ci],
defaults: [yes: false]
defaults: [yes: false, yes_to_deps: false]
}
end

Expand Down Expand Up @@ -148,6 +149,7 @@ defmodule Mix.Tasks.Igniter.Upgrade do
|> Igniter.apply_and_fetch_dependencies(
error_on_abort?: true,
yes: options[:yes],
yes_to_deps: options[:yes_to_deps],
update_deps: Enum.map(package_names, &to_string/1),
update_deps_args: update_deps_args,
force?: true
Expand Down

0 comments on commit ee11c3a

Please sign in to comment.