23
23
! > ``fpm-help`` and ``fpm --list`` help pages below to make sure the help output
24
24
! > is complete and consistent as well.
25
25
module fpm_command_line
26
- use fpm_environment, only : get_os_type, get_env, &
26
+ use fpm_environment, only : get_os_type, get_env, os_is_unix, &
27
27
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
28
28
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
29
29
use M_CLI2, only : set_args, lget, sget, unnamed, remaining, specified
@@ -47,6 +47,7 @@ module fpm_command_line
47
47
fpm_run_settings, &
48
48
fpm_test_settings, &
49
49
fpm_update_settings, &
50
+ fpm_clean_settings, &
50
51
get_command_line_settings
51
52
52
53
type, abstract :: fpm_cmd_settings
@@ -104,6 +105,13 @@ module fpm_command_line
104
105
logical :: clean
105
106
end type
106
107
108
+ type, extends(fpm_cmd_settings) :: fpm_clean_settings
109
+ logical :: unix
110
+ character (len= :), allocatable :: calling_dir ! directory clean called from
111
+ logical :: clean_skip= .false.
112
+ logical :: clean_call= .false.
113
+ end type
114
+
107
115
character (len= :),allocatable :: name
108
116
character (len= :),allocatable :: os_type
109
117
character (len= ibug),allocatable :: names(:)
@@ -113,9 +121,10 @@ module fpm_command_line
113
121
character (len= :), allocatable :: help_new(:), help_fpm(:), help_run(:), &
114
122
& help_test(:), help_build(:), help_usage(:), help_runner(:), &
115
123
& help_text(:), help_install(:), help_help(:), help_update(:), &
116
- & help_list(:), help_list_dash(:), help_list_nodash(:)
124
+ & help_list(:), help_list_dash(:), help_list_nodash(:), &
125
+ & help_clean(:)
117
126
character (len= 20 ),parameter :: manual(* )= [ character (len= 20 ) :: &
118
- & ' ' , ' fpm' , ' new' , ' build' , ' run' , &
127
+ & ' ' , ' fpm' , ' new' , ' build' , ' run' , ' clean ' , &
119
128
& ' test' , ' runner' , ' install' , ' update' , ' list' , ' help' , ' version' ]
120
129
121
130
character (len= :), allocatable :: val_runner, val_compiler, val_flag, val_cflag, val_ldflag, &
@@ -174,6 +183,8 @@ subroutine get_command_line_settings(cmd_settings)
174
183
character (len= 4096 ) :: cmdarg
175
184
integer :: i
176
185
integer :: widest
186
+ integer :: os
187
+ logical :: unix
177
188
type (fpm_install_settings), allocatable :: install_settings
178
189
character (len= :), allocatable :: common_args, compiler_args, run_args, working_dir, &
179
190
& c_compiler, archiver
@@ -184,8 +195,9 @@ subroutine get_command_line_settings(cmd_settings)
184
195
type (error_t), allocatable :: error
185
196
186
197
call set_help()
198
+ os = get_os_type()
187
199
! text for --version switch,
188
- select case (get_os_type() )
200
+ select case (os )
189
201
case (OS_LINUX); os_type = " OS Type: Linux"
190
202
case (OS_MACOS); os_type = " OS Type: macOS"
191
203
case (OS_WINDOWS); os_type = " OS Type: Windows"
@@ -196,6 +208,7 @@ subroutine get_command_line_settings(cmd_settings)
196
208
case (OS_UNKNOWN); os_type = " OS Type: Unknown"
197
209
case default ; os_type = " OS Type: UNKNOWN"
198
210
end select
211
+ unix = os_is_unix(os)
199
212
version_text = [character (len= 80 ) :: &
200
213
& ' Version: 0.5.0, alpha' , &
201
214
& ' Program: fpm(1)' , &
@@ -321,7 +334,7 @@ subroutine get_command_line_settings(cmd_settings)
321
334
select case (size (unnamed))
322
335
case (1 )
323
336
if (lget(' backfill' ))then
324
- name= ' .'
337
+ name= ' .'
325
338
else
326
339
write (stderr,' (*(7x,g0,/))' ) &
327
340
& ' <USAGE> fpm new NAME [[--lib|--src] [--app] [--test] [--example]]|[--full|--bare] [--backfill]'
@@ -424,6 +437,8 @@ subroutine get_command_line_settings(cmd_settings)
424
437
help_text= [character (len= widest) :: help_text, help_help]
425
438
case (' version' )
426
439
help_text= [character (len= widest) :: help_text, version_text]
440
+ case (' clean' )
441
+ help_text= [character (len= widest) :: help_text, help_clean]
427
442
case default
428
443
help_text= [character (len= widest) :: help_text, &
429
444
& ' <ERROR> unknown help topic "' // trim (unnamed(i))// ' "' ]
@@ -469,6 +484,7 @@ subroutine get_command_line_settings(cmd_settings)
469
484
if (lget(' list' ))then
470
485
call printhelp(help_list_dash)
471
486
endif
487
+
472
488
case (' test' )
473
489
call set_args(common_args // compiler_args // run_args // ' --' , &
474
490
help_test,version_text)
@@ -528,6 +544,19 @@ subroutine get_command_line_settings(cmd_settings)
528
544
fetch_only= lget(' fetch-only' ), verbose= lget(' verbose' ), &
529
545
clean= lget(' clean' ))
530
546
547
+ case (' clean' )
548
+ call set_args(common_args // &
549
+ & ' --skip' // &
550
+ & ' --all' , &
551
+ help_clean, version_text)
552
+ allocate (fpm_clean_settings :: cmd_settings)
553
+ call get_current_directory(working_dir, error)
554
+ cmd_settings= fpm_clean_settings( &
555
+ & unix= unix, &
556
+ & calling_dir= working_dir, &
557
+ & clean_skip= lget(' skip' ), &
558
+ clean_call= lget(' all' ))
559
+
531
560
case default
532
561
533
562
if (which(' fpm-' // cmdarg).ne. ' ' )then
@@ -607,6 +636,7 @@ subroutine set_help()
607
636
' test Run the test programs ' , &
608
637
' update Update and manage project dependencies ' , &
609
638
' install Install project ' , &
639
+ ' clean Delete the build ' , &
610
640
' ' , &
611
641
' Enter "fpm --list" for a brief list of subcommand options. Enter ' , &
612
642
' "fpm --help" or "fpm SUBCOMMAND --help" for detailed descriptions. ' , &
@@ -626,6 +656,7 @@ subroutine set_help()
626
656
' [--list] [--compiler COMPILER_NAME] [-- ARGS] ' , &
627
657
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ' , &
628
658
' [options] ' , &
659
+ ' clean [--skip] [--all] ' , &
629
660
' ' ]
630
661
help_usage= [character (len= 80 ) :: &
631
662
' ' ]
@@ -722,12 +753,14 @@ subroutine set_help()
722
753
' + build Compile the packages into the "build/" directory. ' , &
723
754
' + new Create a new Fortran package directory with sample files. ' , &
724
755
' + update Update the project dependencies. ' , &
725
- ' + run Run the local package binaries. defaults to all binaries ' , &
756
+ ' + run Run the local package binaries. Defaults to all binaries ' , &
726
757
' for that release. ' , &
727
758
' + test Run the tests. ' , &
728
759
' + help Alternate to the --help switch for displaying help text. ' , &
729
760
' + list Display brief descriptions of all subcommands. ' , &
730
- ' + install Install project ' , &
761
+ ' + install Install project. ' , &
762
+ ' + clean Delete directories in the "build/" directory, except ' , &
763
+ ' dependencies. Prompts for confirmation to delete. ' , &
731
764
' ' , &
732
765
' Their syntax is ' , &
733
766
' ' , &
@@ -743,7 +776,8 @@ subroutine set_help()
743
776
' help [NAME(s)] ' , &
744
777
' list [--list] ' , &
745
778
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ' , &
746
- ' [options] ' , &
779
+ ' [options] ' , &
780
+ ' clean [--skip] [--all] ' , &
747
781
' ' , &
748
782
' SUBCOMMAND OPTIONS ' , &
749
783
' -C, --directory PATH' , &
@@ -759,6 +793,10 @@ subroutine set_help()
759
793
' the fpm(1) command this shows a brief list of subcommands.' , &
760
794
' --runner CMD Provides a command to prefix program execution paths. ' , &
761
795
' -- ARGS Arguments to pass to executables. ' , &
796
+ ' --skip Delete directories in the build/ directory without ' , &
797
+ ' prompting, but skip dependencies. ' , &
798
+ ' --all Delete directories in the build/ directory without ' , &
799
+ ' prompting, including dependencies. ' , &
762
800
' ' , &
763
801
' VALID FOR ALL SUBCOMMANDS ' , &
764
802
' --help Show help text and exit ' , &
@@ -788,8 +826,8 @@ subroutine set_help()
788
826
' # my build options ' , &
789
827
' options build ' , &
790
828
' options --compiler gfortran ' , &
791
- ' options --flag "-pg -static -pthread -Wunreachable-code -Wunused \ ' , &
792
- ' -Wuninitialized -g -O -fbacktrace -fdump-core -fno-underscoring \ ' , &
829
+ ' options --flag "-pg -static -pthread -Wunreachable-code -Wunused ' , &
830
+ ' -Wuninitialized -g -O -fbacktrace -fdump-core -fno-underscoring ' , &
793
831
' -frecord-marker=4 -L/usr/X11R6/lib -L/usr/X11R6/lib64 -lX11" ' , &
794
832
' ' , &
795
833
' Note --flag would have to be on one line as response files do not ' , &
@@ -809,6 +847,7 @@ subroutine set_help()
809
847
' fpm new --help ' , &
810
848
' fpm run myprogram --profile release -- -x 10 -y 20 --title "my title" ' , &
811
849
' fpm install --prefix ~/.local ' , &
850
+ ' fpm clean --all ' , &
812
851
' ' , &
813
852
' SEE ALSO ' , &
814
853
' ' , &
@@ -998,8 +1037,8 @@ subroutine set_help()
998
1037
' NAME ' , &
999
1038
' new(1) - the fpm(1) subcommand to initialize a new project ' , &
1000
1039
' SYNOPSIS ' , &
1001
- ' fpm new NAME [[--lib|--src] [--app] [--test] [--example]]| ' , &
1002
- ' [--full|--bare][--backfill] ' , &
1040
+ ' fpm new NAME [[--lib|--src] [--app] [--test] [--example]]| ' , &
1041
+ ' [--full|--bare][--backfill] ' , &
1003
1042
' fpm new --help|--version ' , &
1004
1043
' ' , &
1005
1044
' DESCRIPTION ' , &
@@ -1219,7 +1258,22 @@ subroutine set_help()
1219
1258
' ' , &
1220
1259
' fpm install --prefix $PWD --bindir exe' , &
1221
1260
' ' ]
1222
- end subroutine set_help
1261
+ help_clean= [character (len= 80 ) :: &
1262
+ ' NAME' , &
1263
+ ' clean(1) - delete the build' , &
1264
+ ' ' , &
1265
+ ' SYNOPSIS' , &
1266
+ ' fpm clean' , &
1267
+ ' ' , &
1268
+ ' DESCRIPTION' , &
1269
+ ' Prompts the user to confirm deletion of the build. If affirmative,' , &
1270
+ ' directories in the build/ directory are deleted, except dependencies.' , &
1271
+ ' ' , &
1272
+ ' OPTIONS' , &
1273
+ ' --skip delete the build without prompting but skip dependencies.' , &
1274
+ ' --all delete the build without prompting including dependencies.' , &
1275
+ ' ' ]
1276
+ end subroutine set_help
1223
1277
1224
1278
subroutine get_char_arg (var , arg )
1225
1279
character (len= :), allocatable , intent (out ) :: var
0 commit comments