File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 . reduce ( igniter , fn dep , igniter ->
34+ case Igniter.Project.Deps . determine_dep_type_and_version ( dep ) do
35+ { name , version } ->
36+ Igniter.Project.Deps . add_dep ( igniter , { name , version } )
37+
38+ :error ->
39+ raise "Could not determine source for requested package #{ dep } "
40+ end
41+ end )
42+ |> Igniter . add_task ( "deps.get" )
43+ end
44+ end
Original file line number Diff line number Diff line change 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,
11+ """ )
12+ |> assert_has_task ( "deps.get" , [ ] )
13+ end
14+ end
You can’t perform that action at this time.
0 commit comments