Skip to content

Commit 43706a4

Browse files
author
José Valim
committed
mix new no longer generates a supevision tree by default
Please pass `--sup` instead, closes #2074.
1 parent 23f0ff8 commit 43706a4

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Backwards incompatible changes
2323
* [Access] `Kernel.access/2` no longer exists and the `Access` protocol now uses `get/2` instead of `access/2`
2424
* [Kernel] Retrieving docs as `module.__info__(:docs)` is deprecated, instead `Code.get_docs/2` must be used
25+
* [Mix] `mix new` no longer generates a supevision tree by default, please pass `--sup` instead
2526

2627
# v0.13.3 (2014-05-24)
2728

lib/mix/lib/mix/tasks/new.ex

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ defmodule Mix.Tasks.New do
1616
application name and module name will be retrieved
1717
from the path, unless `--module` is given.
1818
19-
A `--bare` option can be given to not generate an OTP
20-
application skeleton. Normally an app is generated with
21-
a supervisor and an application module that starts the
22-
supervisor.
19+
A `--sup` option can be given to generate an OTP application
20+
skeleton including a supervision tree. Normally an app is
21+
generated without a supervisor and without the app callback.
2322
2423
An `--umbrella` option can be given to generate an
2524
umbrella project.
@@ -32,13 +31,13 @@ defmodule Mix.Tasks.New do
3231
3332
mix new hello_world --module HelloWorld
3433
35-
To generate an app without supervisor and application behaviours:
34+
To generate an app with supervisor and application callback:
3635
37-
mix new hello_world --bare
36+
mix new hello_world --sup
3837
3938
"""
4039
def run(argv) do
41-
{opts, argv, _} = OptionParser.parse(argv, switches: [bare: :boolean, umbrella: :boolean])
40+
{opts, argv, _} = OptionParser.parse(argv, switches: [sup: :boolean, umbrella: :boolean])
4241

4342
case argv do
4443
[] ->
@@ -60,7 +59,7 @@ defmodule Mix.Tasks.New do
6059

6160
defp do_generate(app, path, opts) do
6261
mod = opts[:module] || camelize(app)
63-
assigns = [app: app, mod: mod, otp_app: otp_app(mod, !!opts[:bare])]
62+
assigns = [app: app, mod: mod, otp_app: otp_app(mod, !!opts[:sup])]
6463

6564
create_file "README.md", readme_template(assigns)
6665
create_file ".gitignore", gitignore_text
@@ -71,19 +70,20 @@ defmodule Mix.Tasks.New do
7170
create_file "mix.exs", mixfile_template(assigns)
7271
end
7372

73+
create_directory "config"
74+
create_file "config/config.exs", config_template(assigns)
75+
7476
create_directory "lib"
7577

76-
if opts[:bare] do
77-
create_file "lib/#{app}.ex", lib_template(assigns)
78+
if opts[:sup] do
79+
create_file "lib/#{app}.ex", lib_sup_template(assigns)
7880
else
79-
create_file "lib/#{app}.ex", lib_app_template(assigns)
80-
create_directory "config"
81-
create_file "config/config.exs", config_template(assigns)
81+
create_file "lib/#{app}.ex", lib_template(assigns)
8282
end
8383

8484
create_directory "test"
8585
create_file "test/test_helper.exs", test_helper_template(assigns)
86-
create_file "test/#{app}_test.exs", test_lib_template(assigns)
86+
create_file "test/#{app}_test.exs", test_template(assigns)
8787

8888
Mix.shell.info """
8989
@@ -97,11 +97,11 @@ defmodule Mix.Tasks.New do
9797
"""
9898
end
9999

100-
defp otp_app(_mod, true) do
100+
defp otp_app(_mod, false) do
101101
" [applications: []]"
102102
end
103103

104-
defp otp_app(mod, false) do
104+
defp otp_app(mod, true) do
105105
" [applications: [],\n mod: {#{mod}, []}]"
106106
end
107107

@@ -111,7 +111,7 @@ defmodule Mix.Tasks.New do
111111

112112
create_file ".gitignore", gitignore_text
113113
create_file "README.md", readme_template(assigns)
114-
create_file "mix.exs", mixfile_umbrella_template(assigns)
114+
create_file "mix.exs", mixfile_umbrella_template(assigns)
115115

116116
create_directory "apps"
117117

@@ -292,7 +292,7 @@ defmodule Mix.Tasks.New do
292292
end
293293
"""
294294

295-
embed_template :lib_app, """
295+
embed_template :lib_sup, """
296296
defmodule <%= @mod %> do
297297
use Application
298298
@@ -314,7 +314,7 @@ defmodule Mix.Tasks.New do
314314
end
315315
"""
316316

317-
embed_template :test_lib, """
317+
embed_template :test, """
318318
defmodule <%= @mod %>Test do
319319
use ExUnit.Case
320320
@@ -325,6 +325,6 @@ defmodule Mix.Tasks.New do
325325
"""
326326

327327
embed_template :test_helper, """
328-
ExUnit.start
328+
ExUnit.start()
329329
"""
330330
end

lib/mix/test/mix/cli_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ defmodule Mix.CLITest do
125125
end
126126
end
127127

128-
test "new --bare with tests" do
129-
in_tmp "new_with_tests", fn ->
130-
output = mix "new --bare ."
131-
assert output =~ "* creating lib/new_with_tests.ex"
128+
test "new --sup with tests" do
129+
in_tmp "sup_with_tests", fn ->
130+
output = mix "new --sup ."
131+
assert output =~ "* creating lib/sup_with_tests.ex"
132132

133133
output = mix "test"
134-
assert File.regular?("_build/test/lib/new_with_tests/ebin/Elixir.NewWithTests.beam")
134+
assert File.regular?("_build/test/lib/sup_with_tests/ebin/Elixir.SupWithTests.beam")
135135
assert output =~ "1 tests, 0 failures"
136136
end
137137
end

lib/mix/test/mix/tasks/new_test.exs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,17 @@ defmodule Mix.Tasks.NewTest do
55

66
test "new" do
77
in_tmp "new", fn ->
8-
Mix.Tasks.New.run ["hello_world"]
8+
Mix.Tasks.New.run ["hello_world", "--bare"]
99

1010
assert_file "hello_world/mix.exs", fn(file) ->
1111
assert file =~ "app: :hello_world"
1212
assert file =~ "version: \"0.0.1\""
13-
assert file =~ "mod: {HelloWorld, []}"
1413
end
1514

1615
assert_file "hello_world/README.md", ~r/# HelloWorld/
1716
assert_file "hello_world/.gitignore"
1817

19-
assert_file "hello_world/lib/hello_world.ex", fn(file) ->
20-
assert file =~ "defmodule HelloWorld do"
21-
assert file =~ "use Application"
22-
assert file =~ "Supervisor.start_link(children, opts)"
23-
end
18+
assert_file "hello_world/lib/hello_world.ex", ~r/defmodule HelloWorld do/
2419

2520
assert_file "hello_world/test/test_helper.exs", ~r/HelloWorld.start/
2621
assert_file "hello_world/test/hello_world_test.exs", ~r/defmodule HelloWorldTest do/
@@ -30,19 +25,24 @@ defmodule Mix.Tasks.NewTest do
3025
end
3126
end
3227

33-
test "new with --bare" do
34-
in_tmp "new bare", fn ->
35-
Mix.Tasks.New.run ["hello_world", "--bare"]
28+
test "new with --sup" do
29+
in_tmp "new sup", fn ->
30+
Mix.Tasks.New.run ["hello_world", "--sup"]
3631

3732
assert_file "hello_world/mix.exs", fn(file) ->
3833
assert file =~ "app: :hello_world"
3934
assert file =~ "version: \"0.0.1\""
35+
assert file =~ "mod: {HelloWorld, []}"
4036
end
4137

4238
assert_file "hello_world/README.md", ~r/# HelloWorld/
4339
assert_file "hello_world/.gitignore"
4440

45-
assert_file "hello_world/lib/hello_world.ex", ~r/defmodule HelloWorld do/
41+
assert_file "hello_world/lib/hello_world.ex", fn(file) ->
42+
assert file =~ "defmodule HelloWorld do"
43+
assert file =~ "use Application"
44+
assert file =~ "Supervisor.start_link(children, opts)"
45+
end
4646

4747
assert_file "hello_world/test/test_helper.exs", ~r/HelloWorld.start/
4848
assert_file "hello_world/test/hello_world_test.exs", ~r/defmodule HelloWorldTest do/

0 commit comments

Comments
 (0)