@@ -16,10 +16,9 @@ defmodule Mix.Tasks.New do
16
16
application name and module name will be retrieved
17
17
from the path, unless `--module` is given.
18
18
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.
23
22
24
23
An `--umbrella` option can be given to generate an
25
24
umbrella project.
@@ -32,13 +31,13 @@ defmodule Mix.Tasks.New do
32
31
33
32
mix new hello_world --module HelloWorld
34
33
35
- To generate an app without supervisor and application behaviours :
34
+ To generate an app with supervisor and application callback :
36
35
37
- mix new hello_world --bare
36
+ mix new hello_world --sup
38
37
39
38
"""
40
39
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 ] )
42
41
43
42
case argv do
44
43
[ ] ->
@@ -60,7 +59,7 @@ defmodule Mix.Tasks.New do
60
59
61
60
defp do_generate ( app , path , opts ) do
62
61
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 ] ) ]
64
63
65
64
create_file "README.md" , readme_template ( assigns )
66
65
create_file ".gitignore" , gitignore_text
@@ -71,19 +70,20 @@ defmodule Mix.Tasks.New do
71
70
create_file "mix.exs" , mixfile_template ( assigns )
72
71
end
73
72
73
+ create_directory "config"
74
+ create_file "config/config.exs" , config_template ( assigns )
75
+
74
76
create_directory "lib"
75
77
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 )
78
80
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 )
82
82
end
83
83
84
84
create_directory "test"
85
85
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 )
87
87
88
88
Mix . shell . info """
89
89
@@ -97,11 +97,11 @@ defmodule Mix.Tasks.New do
97
97
"""
98
98
end
99
99
100
- defp otp_app ( _mod , true ) do
100
+ defp otp_app ( _mod , false ) do
101
101
" [applications: []]"
102
102
end
103
103
104
- defp otp_app ( mod , false ) do
104
+ defp otp_app ( mod , true ) do
105
105
" [applications: [],\n mod: {#{ mod } , []}]"
106
106
end
107
107
@@ -111,7 +111,7 @@ defmodule Mix.Tasks.New do
111
111
112
112
create_file ".gitignore" , gitignore_text
113
113
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 )
115
115
116
116
create_directory "apps"
117
117
@@ -292,7 +292,7 @@ defmodule Mix.Tasks.New do
292
292
end
293
293
"""
294
294
295
- embed_template :lib_app , """
295
+ embed_template :lib_sup , """
296
296
defmodule <%= @mod %> do
297
297
use Application
298
298
@@ -314,7 +314,7 @@ defmodule Mix.Tasks.New do
314
314
end
315
315
"""
316
316
317
- embed_template :test_lib , """
317
+ embed_template :test , """
318
318
defmodule <%= @mod %>Test do
319
319
use ExUnit.Case
320
320
@@ -325,6 +325,6 @@ defmodule Mix.Tasks.New do
325
325
"""
326
326
327
327
embed_template :test_helper , """
328
- ExUnit.start
328
+ ExUnit.start()
329
329
"""
330
330
end
0 commit comments