Skip to content

Commit 48a7921

Browse files
urbanjostLKedward
authored andcommitted
simplify initializing git(1) repository
1 parent 51180c0 commit 48a7921

File tree

2 files changed

+67
-39
lines changed

2 files changed

+67
-39
lines changed

fpm/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build/*
2-
*/FODDER/*
2+
FODDER/*

fpm/src/fpm/cmd/new.f90

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,50 @@ module fpm_cmd_new
1010

1111
contains
1212

13-
subroutine cmd_new(settings) ! --with-executable F --with-test F '
13+
subroutine cmd_new(settings)
1414
type(fpm_new_settings), intent(in) :: settings
1515
character(len=:),allocatable :: bname ! baeename of NAME
1616
character(len=:),allocatable :: message(:)
1717
character(len=:),allocatable :: littlefile(:)
1818

1919
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 ?'
2224
return
2325
elseif(is_dir(settings%name) .and. settings%backfill )then
2426
write(*,'(*(g0))')'backfilling ',settings%name
2527
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.'
2730
return
2831
else
29-
call mkdir(settings%name) ! make new directory
32+
! make new directory
33+
call mkdir(settings%name)
3034
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().
3340
bname=basename(settings%name)
3441

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
3746

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/*'])
3949

4050
littlefile=[character(len=80) :: '# '//bname, 'My cool new project!']
4151

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)
4354

44-
message=[character(len=80) :: & ! start building NAME/fpm.toml
55+
! start building NAME/fpm.toml
56+
message=[character(len=80) :: &
4557
&'name = "'//bname//'" ', &
4658
&'version = "0.1.0" ', &
4759
&'license = "license" ', &
@@ -53,11 +65,13 @@ subroutine cmd_new(settings) ! --with-executable F --with-test F '
5365

5466
if(settings%with_lib)then
5567
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, &
5770
&'[library] ', &
5871
&'source-dir="src" ', &
5972
&'']
60-
littlefile=[character(len=80) :: & ! create placeholder module src/bname.f90
73+
! create placeholder module src/bname.f90
74+
littlefile=[character(len=80) :: &
6175
&'module '//bname, &
6276
&' implicit none', &
6377
&' private', &
@@ -68,39 +82,44 @@ subroutine cmd_new(settings) ! --with-executable F --with-test F '
6882
&' print *, "Hello, '//bname//'!"', &
6983
&' end subroutine say_hello', &
7084
&'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)
7388
endif
7489

7590
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, &
7896
&'[[test]] ', &
7997
&'name="runTests" ', &
8098
&'source-dir="test" ', &
8199
&'main="main.f90" ', &
82100
&'']
83101

84-
littlefile=[character(len=80) :: &
102+
littlefile=[character(len=80) :: &
85103
&'program main', &
86104
&'implicit none', &
87105
&'', &
88106
&'print *, "Put some tests in here!"', &
89107
&'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)
92110
endif
93111

94112
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, &
97117
&'[[executable]] ', &
98118
&'name="'//bname//'" ', &
99119
&'source-dir="app" ', &
100120
&'main="main.f90" ', &
101121
&'']
102122

103-
104123
if(exists(bname//'/src/'))then
105124
littlefile=[character(len=80) :: &
106125
&'program main', &
@@ -119,9 +138,11 @@ subroutine cmd_new(settings) ! --with-executable F --with-test F '
119138
endif
120139
call warnwrite(join_path(settings%name, 'app/main.f90'), littlefile)
121140
endif
122-
call warnwrite(join_path(settings%name, 'fpm.toml'), message) ! now that built it write NAME/fpm.toml
123141

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)
125146
contains
126147

127148
subroutine warnwrite(fname,data)
@@ -131,14 +152,17 @@ subroutine warnwrite(fname,data)
131152
if(.not.exists(fname))then
132153
call filewrite(fname,data)
133154
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'
135157
endif
136158

137159
end subroutine warnwrite
138160

139161
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+
142166
character(len=*),intent(in) :: filename
143167
character(len=*),intent(in) :: filedata(:)
144168
integer :: lun, i, ios
@@ -149,29 +173,33 @@ subroutine filewrite(filename,filedata)
149173
if(filename.ne.' ')then
150174
open(file=filename, &
151175
& 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
157181
& iostat=ios, &
158182
& iomsg=message)
159183
else
160184
lun=stdout
161185
ios=0
162186
endif
163187
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)
165190
error stop 1
166191
endif
167-
do i=1,size(filedata) ! write file
192+
! write file
193+
do i=1,size(filedata)
168194
write(lun,'(a)',iostat=ios,iomsg=message)trim(filedata(i))
169195
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)
171198
error stop 4
172199
endif
173200
enddo
174-
close(unit=lun,iostat=ios,iomsg=message) ! close file
201+
! close file
202+
close(unit=lun,iostat=ios,iomsg=message)
175203
if(ios.ne.0)then
176204
write(stderr,'(*(a:,1x))')'*filewrite* error:',trim(message)
177205
error stop 2

0 commit comments

Comments
 (0)