@@ -10,38 +10,50 @@ module fpm_cmd_new
10
10
11
11
contains
12
12
13
- subroutine cmd_new (settings ) ! --with-executable F --with-test F '
13
+ subroutine cmd_new (settings )
14
14
type (fpm_new_settings), intent (in ) :: settings
15
15
character (len= :),allocatable :: bname ! baeename of NAME
16
16
character (len= :),allocatable :: message(:)
17
17
character (len= :),allocatable :: littlefile(:)
18
18
19
19
if (exists(settings% name) .and. .not. settings% backfill )then
20
- write (stderr,' (*(g0,1x))' )' fpm::new<ERROR>' ,settings% name,' already exists.'
21
- write (stderr,' (*(g0,1x))' )' perhaps you wanted to add --backfill ?'
20
+ write (stderr,' (*(g0,1x))' )&
21
+ & ' ERROR: ' ,settings% name,' already exists.'
22
+ write (stderr,' (*(g0,1x))' )&
23
+ & ' perhaps you wanted to add --backfill ?'
22
24
return
23
25
elseif (is_dir(settings% name) .and. settings% backfill )then
24
26
write (* ,' (*(g0))' )' backfilling ' ,settings% name
25
27
elseif (exists(settings% name) )then
26
- write (stderr,' (*(g0,1x))' )' fpm::new<ERROR>' ,settings% name,' already exists and is not a directory.'
28
+ write (stderr,' (*(g0,1x))' )&
29
+ & ' ERROR: ' ,settings% name,' already exists and is not a directory.'
27
30
return
28
31
else
29
- call mkdir(settings% name) ! make new directory
32
+ ! make new directory
33
+ call mkdir(settings% name)
30
34
endif
31
- call run(' cd ' // settings% name) ! change to new directory as a test. System dependent potentially
32
- ! ! NOTE: need some system routines to handle filenames like "." like realpath() or getcwd().
35
+
36
+ ! change to new directory as a test. System dependent potentially
37
+ call run(' cd ' // settings% name)
38
+ ! ! NOTE: need some system routines to handle filenames like "."
39
+ ! ! like realpath() or getcwd().
33
40
bname= basename(settings% name)
34
41
35
- ! ! weird gfortran bug?? lines truncated to concatenated string length, not 80
36
- ! ! hit some weird gfortran bug when littlefile data was an argument to warnwrite(3f), ok when a variable
42
+ ! ! weird gfortran bug?? lines truncated to concatenated string length,
43
+ ! ! not 80
44
+ ! ! hit some weird gfortran bug when littlefile data was an argument
45
+ ! ! to warnwrite(3f), ok when a variable
37
46
38
- call warnwrite(join_path(settings% name, ' .gitignore' ), [' build/*' ]) ! create NAME/.gitignore file
47
+ ! create NAME/.gitignore file
48
+ call warnwrite(join_path(settings% name, ' .gitignore' ), [' build/*' ])
39
49
40
50
littlefile= [character (len= 80 ) :: ' # ' // bname, ' My cool new project!' ]
41
51
42
- call warnwrite(join_path(settings% name, ' README.md' ), littlefile) ! create NAME/README.md
52
+ ! create NAME/README.md
53
+ call warnwrite(join_path(settings% name, ' README.md' ), littlefile)
43
54
44
- message= [character (len= 80 ) :: & ! start building NAME/fpm.toml
55
+ ! start building NAME/fpm.toml
56
+ message= [character (len= 80 ) :: &
45
57
&' name = "' // bname// ' " ' , &
46
58
&' version = "0.1.0" ' , &
47
59
&' license = "license" ' , &
@@ -53,11 +65,13 @@ subroutine cmd_new(settings) ! --with-executable F --with-test F '
53
65
54
66
if (settings% with_lib)then
55
67
call mkdir(join_path(settings% name,' src' ) )
56
- message= [character (len= 80 ) :: message, & ! create next section of fpm.toml
68
+ ! create next section of fpm.toml
69
+ message= [character (len= 80 ) :: message, &
57
70
&' [library] ' , &
58
71
&' source-dir="src" ' , &
59
72
&' ' ]
60
- littlefile= [character (len= 80 ) :: & ! create placeholder module src/bname.f90
73
+ ! create placeholder module src/bname.f90
74
+ littlefile= [character (len= 80 ) :: &
61
75
&' module ' // bname, &
62
76
&' implicit none' , &
63
77
&' private' , &
@@ -68,39 +82,44 @@ subroutine cmd_new(settings) ! --with-executable F --with-test F '
68
82
&' print *, "Hello, ' // bname// ' !"' , &
69
83
&' end subroutine say_hello' , &
70
84
&' end module ' // bname]
71
- ! a proposed alternative default
72
- call warnwrite(join_path(settings% name, ' src' , bname// ' .f90' ), littlefile) ! create NAME/src/NAME.f90
85
+ ! create NAME/src/NAME.f90
86
+ call warnwrite(join_path(settings% name, ' src' , bname// ' .f90' ),&
87
+ & littlefile)
73
88
endif
74
89
75
90
if (settings% with_test)then
76
- call mkdir(join_path(settings% name, ' test' )) ! create NAME/test or stop
77
- message= [character (len= 80 ) :: message, & ! create next section of fpm.toml
91
+
92
+ ! create NAME/test or stop
93
+ call mkdir(join_path(settings% name, ' test' ))
94
+ ! create next section of fpm.toml
95
+ message= [character (len= 80 ) :: message, &
78
96
&' [[test]] ' , &
79
97
&' name="runTests" ' , &
80
98
&' source-dir="test" ' , &
81
99
&' main="main.f90" ' , &
82
100
&' ' ]
83
101
84
- littlefile= [character (len= 80 ) :: &
102
+ littlefile= [character (len= 80 ) :: &
85
103
&' program main' , &
86
104
&' implicit none' , &
87
105
&' ' , &
88
106
&' print *, "Put some tests in here!"' , &
89
107
&' end program main' ]
90
- ! a proposed alternative default a little more substantive
91
- call warnwrite(join_path(settings% name, ' test/main.f90' ), littlefile) ! create NAME/test/main.f90
108
+ ! create NAME/test/main.f90
109
+ call warnwrite(join_path(settings% name, ' test/main.f90' ), littlefile)
92
110
endif
93
111
94
112
if (settings% with_executable)then
95
- call mkdir(join_path(settings% name, ' app' )) ! create NAME/app or stop
96
- message= [character (len= 80 ) :: message, & ! create next section of fpm.toml
113
+ ! create next section of fpm.toml
114
+ call mkdir(join_path(settings% name, ' app' ))
115
+ ! create NAME/app or stop
116
+ message= [character (len= 80 ) :: message, &
97
117
&' [[executable]] ' , &
98
118
&' name="' // bname// ' " ' , &
99
119
&' source-dir="app" ' , &
100
120
&' main="main.f90" ' , &
101
121
&' ' ]
102
122
103
-
104
123
if (exists(bname// ' /src/' ))then
105
124
littlefile= [character (len= 80 ) :: &
106
125
&' program main' , &
@@ -119,9 +138,11 @@ subroutine cmd_new(settings) ! --with-executable F --with-test F '
119
138
endif
120
139
call warnwrite(join_path(settings% name, ' app/main.f90' ), littlefile)
121
140
endif
122
- call warnwrite(join_path(settings% name, ' fpm.toml' ), message) ! now that built it write NAME/fpm.toml
123
141
124
- call run(' cd ' // settings% name // ' &&git init' ) ! assumes these commands work on all systems and git(1) is installed
142
+ ! now that built it write NAME/fpm.toml
143
+ call warnwrite(join_path(settings% name, ' fpm.toml' ), message)
144
+ ! assumes git(1) is installed and in path
145
+ call run(' git init ' // settings% name)
125
146
contains
126
147
127
148
subroutine warnwrite (fname ,data )
@@ -131,14 +152,17 @@ subroutine warnwrite(fname,data)
131
152
if (.not. exists(fname))then
132
153
call filewrite(fname,data )
133
154
else
134
- write (stderr,' (*(g0,1x))' )' fpm::new<INFO>' ,fname,' already exists. Not overwriting'
155
+ write (stderr,' (*(g0,1x))' )' INFO: ' ,fname,&
156
+ & ' already exists. Not overwriting'
135
157
endif
136
158
137
159
end subroutine warnwrite
138
160
139
161
subroutine filewrite (filename ,filedata )
140
- use ,intrinsic :: iso_fortran_env, only : stdin= >input_unit, stdout= >output_unit, stderr= >error_unit
141
- ! write filedata to file filename
162
+ ! procedure to write filedata to file filename
163
+ use ,intrinsic :: iso_fortran_env, only : &
164
+ & stdin= >input_unit, stdout= >output_unit, stderr= >error_unit
165
+
142
166
character (len=* ),intent (in ) :: filename
143
167
character (len=* ),intent (in ) :: filedata(:)
144
168
integer :: lun, i, ios
@@ -149,29 +173,33 @@ subroutine filewrite(filename,filedata)
149
173
if (filename.ne. ' ' )then
150
174
open (file= filename, &
151
175
& newunit= lun, &
152
- & form= ' formatted' , & ! FORM = FORMATTED | UNFORMATTED
153
- & access= ' sequential' , & ! ACCESS = SEQUENTIAL | DIRECT | STREAM
154
- & action= ' write' , & ! ACTION = READ|WRITE | READWRITE
155
- & position= ' rewind' , & ! POSITION = ASIS | REWIND | APPEND
156
- & status= ' new' , & ! STATUS = NEW | REPLACE | OLD | SCRATCH | UNKNOWN
176
+ & form= ' formatted' , & ! FORM = FORMATTED | UNFORMATTED
177
+ & access= ' sequential' , & ! ACCESS = SEQUENTIAL| DIRECT | STREAM
178
+ & action= ' write' , & ! ACTION = READ|WRITE| READWRITE
179
+ & position= ' rewind' , & ! POSITION= ASIS | REWIND | APPEND
180
+ & status= ' new' , & ! STATUS = NEW| REPLACE| OLD| SCRATCH| UNKNOWN
157
181
& iostat= ios, &
158
182
& iomsg= message)
159
183
else
160
184
lun= stdout
161
185
ios= 0
162
186
endif
163
187
if (ios.ne. 0 )then
164
- write (stderr,' (*(a:,1x))' )' *filewrite* error:' ,filename,trim (message)
188
+ write (stderr,' (*(a:,1x))' )&
189
+ & ' *filewrite* error:' ,filename,trim (message)
165
190
error stop 1
166
191
endif
167
- do i= 1 ,size (filedata) ! write file
192
+ ! write file
193
+ do i= 1 ,size (filedata)
168
194
write (lun,' (a)' ,iostat= ios,iomsg= message)trim (filedata(i))
169
195
if (ios.ne. 0 )then
170
- write (stderr,' (*(a:,1x))' )' *filewrite* error:' ,filename,trim (message)
196
+ write (stderr,' (*(a:,1x))' )&
197
+ & ' *filewrite* error:' ,filename,trim (message)
171
198
error stop 4
172
199
endif
173
200
enddo
174
- close (unit= lun,iostat= ios,iomsg= message) ! close file
201
+ ! close file
202
+ close (unit= lun,iostat= ios,iomsg= message)
175
203
if (ios.ne. 0 )then
176
204
write (stderr,' (*(a:,1x))' )' *filewrite* error:' ,trim (message)
177
205
error stop 2
0 commit comments