Skip to content

Commit 89f2d00

Browse files
committed
feat: add igniter.add task
1 parent 005fbdc commit 89f2d00

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

lib/mix/tasks/igniter.add.ex

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
defmodule Mix.Tasks.Igniter.Add do
2+
use Igniter.Mix.Task
3+
4+
@example "mix igniter.add dep1 dep2"
5+
6+
@shortdoc "Adds the provided deps to `mix.exs`"
7+
@moduledoc """
8+
#{@shortdoc}
9+
10+
This is only useful when you want to add a dependency without running its installer, since `igniter.install` already adds the dependency to `mix.exs`.
11+
12+
This task also gets the dependencies after completion.
13+
14+
## Example
15+
16+
```bash
17+
#{@example}
18+
```
19+
"""
20+
21+
@impl Igniter.Mix.Task
22+
def info(_argv, _composing_task) do
23+
%Igniter.Mix.Task.Info{
24+
positional: [deps: [rest: true]]
25+
}
26+
end
27+
28+
@impl Igniter.Mix.Task
29+
def igniter(igniter) do
30+
igniter.args.positional.deps
31+
|> Enum.join(",")
32+
|> String.split(",")
33+
|> Enum.map(&String.to_atom/1)
34+
|> Enum.reduce(igniter, fn name, igniter ->
35+
Igniter.Project.Deps.add_dep(igniter, {name, ">= 0.0.0"})
36+
end)
37+
|> Igniter.add_task("deps.get")
38+
end
39+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule Mix.Tasks.Igniter.AddTest do
2+
use ExUnit.Case
3+
import Igniter.Test
4+
5+
test "adds dependencies" do
6+
test_project()
7+
|> apply_igniter!()
8+
|> Igniter.compose_task("igniter.add", ["req"])
9+
|> assert_has_patch("mix.exs", """
10+
+ | {:req, ">= 0.0.0"}
11+
""")
12+
|> assert_has_task("deps.get", [])
13+
end
14+
end

0 commit comments

Comments
 (0)