Skip to content

Commit 3167d78

Browse files
author
alexrp
committed
Add a --force option to mix local.install.
Useful for makefiles.
1 parent b535f07 commit 3167d78

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/mix/lib/mix/tasks/local.install.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,31 @@ defmodule Mix.Tasks.Local.Install do
1717
1818
mix some_task
1919
20+
## Command line options
21+
22+
* `--force` forces installation without a shell prompt. Primarily
23+
intended for automation in build systems like Make.
24+
2025
"""
2126

2227
def run(argv) do
23-
{ _, argv } = OptionParser.parse(argv)
28+
{ opts, argv } = OptionParser.parse(argv, switches: [force: :boolean])
2429
case argv do
2530
[] ->
2631
raise Mix.Error, message: "expected PATH to be given, please use `mix local.install PATH`"
2732
[path|_] ->
28-
do_install path
33+
do_install path, opts
2934
end
3035
end
3136

32-
defp do_install(path) do
37+
defp do_install(path, opts) do
3338
beam = Mix.Utils.read_path(path)
3439
{ :module, module } = get_module(path, beam)
3540

3641
validate_module_name!(path, module)
3742
task_name = Mix.Task.task_name(module)
3843

39-
if Mix.shell.yes?("Are you sure you want to install task #{inspect task_name}?") do
44+
if opts[:force] || Mix.shell.yes?("Are you sure you want to install task #{inspect task_name}?") do
4045
tasks = Mix.Local.tasks_path
4146
File.mkdir_p! tasks
4247
create_file Path.join(tasks, "#{module}.beam"), beam
@@ -60,4 +65,4 @@ defmodule Mix.Tasks.Local.Install do
6065
raise Mix.Error, message: "expected a Mix.Tasks module at #{path}, got #{other}"
6166
end
6267
end
63-
end
68+
end

0 commit comments

Comments
 (0)