/
deps.update.ex
74 lines (55 loc) · 2.04 KB
/
deps.update.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
defmodule Mix.Tasks.Deps.Update do
use Mix.Task
@shortdoc "Updates the given dependencies"
@moduledoc """
Updates the given dependencies.
The given dependencies and the projects they depend on will
be unlocked and updated to the latest version according to their
version requirements.
Since this is a destructive action, updating all dependencies
only occurs when the `--all` command line option is passed.
All dependencies are automatically recompiled after update.
## mix deps.unlock + mix deps.get
Upgrading a dependency often requires the projects it depends on
to upgrade too. If you would rather update a single dependency and
not touch its children, you can explicitly unlock the single dependency
and run `mix deps.get`:
$ mix deps.unlock some_dep
$ mix deps.get
## Command line options
* `--all` - updates all dependencies
* `--only` - only fetches dependencies for given environment
* `--target` - only fetches dependencies for given target
* `--no-archives-check` - does not check archives before fetching deps
"""
@impl true
def run(args) do
unless "--no-archives-check" in args do
Mix.Task.run("archive.check", args)
end
Mix.Project.get!()
{opts, rest, _} =
OptionParser.parse(args, switches: [all: :boolean, only: :string, target: :string])
fetch_opts =
for {switch, key} <- [only: :env, target: :target],
value = opts[switch],
do: {key, :"#{value}"}
cond do
opts[:all] ->
Mix.Dep.Fetcher.all(Mix.Dep.Lock.read(), %{}, fetch_opts)
rest != [] ->
{old, new} = Map.split(Mix.Dep.Lock.read(), to_app_names(rest))
Mix.Dep.Fetcher.by_name(rest, old, new, fetch_opts)
true ->
Mix.raise(
"\"mix deps.update\" expects dependencies as arguments or " <>
"the --all option to update all dependencies"
)
end
end
defp to_app_names(given) do
Enum.map(given, fn app ->
if is_binary(app), do: String.to_atom(app), else: app
end)
end
end