Skip to content

Commit e8c3ed2

Browse files
author
José Valim
committed
Merge pull request #1714 from pminten/mix-new-default-sup
Make --sup the default for mix
2 parents 9839bfa + 3d583e7 commit e8c3ed2

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ defmodule Mix.Tasks.New do
1010
Creates a new Elixir project.
1111
It expects the path of the project as argument.
1212
13-
mix new PATH [--sup] [--module MODULE] [--umbrella]
13+
mix new PATH [--bare] [--module MODULE] [--umbrella]
1414
1515
A project at the given PATH will be created. The
1616
application name and module name will be retrieved
1717
from the path, unless `--module` is given.
1818
19-
A `--sup` option can be given to generate an
20-
app with a supervisor and an application module
21-
that starts the supervisor.
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.
2223
2324
An `--umbrella` option can be given to generate an
2425
umbrella project.
@@ -31,13 +32,13 @@ defmodule Mix.Tasks.New do
3132
3233
mix new hello_world --module HelloWorld
3334
34-
To generate an app with supervisor and application behaviours:
35+
To generate an app without supervisor and application behaviours:
3536
36-
mix new hello_world --sup
37+
mix new hello_world --bare
3738
3839
"""
3940
def run(argv) do
40-
{ opts, argv, _ } = OptionParser.parse(argv, switches: [sup: :boolean, umbrella: :boolean])
41+
{ opts, argv, _ } = OptionParser.parse(argv, switches: [bare: :boolean, umbrella: :boolean])
4142

4243
case argv do
4344
[] ->
@@ -59,7 +60,7 @@ defmodule Mix.Tasks.New do
5960

6061
defp do_generate(app, path, opts) do
6162
mod = opts[:module] || camelize(app)
62-
otp_app = if opts[:sup], do: "[mod: { #{mod}, [] }]", else: "[]"
63+
otp_app = if opts[:bare], do: "[]", else: "[mod: { #{mod}, [] }]"
6364
assigns = [app: app, mod: mod, otp_app: otp_app]
6465

6566
create_file "README.md", readme_template(assigns)
@@ -68,12 +69,12 @@ defmodule Mix.Tasks.New do
6869

6970
create_directory "lib"
7071

71-
if opts[:sup] do
72+
if opts[:bare] do
73+
create_file "lib/#{app}.ex", lib_template(assigns)
74+
else
7275
create_file "lib/#{app}.ex", lib_app_template(assigns)
7376
create_directory "lib/#{app}"
7477
create_file "lib/#{app}/supervisor.ex", lib_supervisor_template(assigns)
75-
else
76-
create_file "lib/#{app}.ex", lib_template(assigns)
7778
end
7879

7980
create_directory "test"

lib/mix/test/mix/cli_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,24 @@ defmodule Mix.CLITest do
5555
in_tmp "new_with_tests", fn ->
5656
output = mix "new ."
5757
assert output =~ "* creating lib/new_with_tests.ex"
58+
assert output =~ "* creating lib/new_with_tests/supervisor.ex"
5859

59-
output = mix "test"
60+
output = mix "test test/new_with_tests_test.exs --cover"
6061
assert File.regular?("ebin/Elixir.NewWithTests.beam")
6162
assert output =~ "1 tests, 0 failures"
63+
assert output =~ "Generating cover results ... ok"
64+
assert File.regular?("cover/Elixir.NewWithTests.html")
6265
end
6366
end
6467

65-
test "new --sup with tests smoke test" do
68+
test "new --bare with tests smoke test" do
6669
in_tmp "new_with_tests", fn ->
67-
output = mix "new . --sup"
70+
output = mix "new --bare ."
6871
assert output =~ "* creating lib/new_with_tests.ex"
69-
assert output =~ "* creating lib/new_with_tests/supervisor.ex"
7072

71-
output = mix "test test/new_with_tests_test.exs --cover"
73+
output = mix "test"
7274
assert File.regular?("ebin/Elixir.NewWithTests.beam")
7375
assert output =~ "1 tests, 0 failures"
74-
assert output =~ "Generating cover results ... ok"
75-
assert File.regular?("cover/Elixir.NewWithTests.html")
7676
end
7777
end
7878

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Code.require_file "../../test_helper.exs", __DIR__
33
defmodule Mix.Tasks.NewTest do
44
use MixTest.Case
55

6-
test "new with underscore" do
6+
test "new with underscore and --bare" do
77
in_tmp "new with underscore", 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"
@@ -25,9 +25,9 @@ defmodule Mix.Tasks.NewTest do
2525
end
2626
end
2727

28-
test "new with --sup" do
28+
test "new without --bare" do
2929
in_tmp "new with underscore", fn ->
30-
Mix.Tasks.New.run ["hello_world", "--sup"]
30+
Mix.Tasks.New.run ["hello_world"]
3131
3232
assert_file "hello_world/mix.exs", fn(file) ->
3333
assert file =~ "app: :hello_world"

0 commit comments

Comments
 (0)