2323! > ``fpm-help`` and ``fpm --list`` help pages below to make sure the help output
2424! > is complete and consistent as well.
2525module 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, &
2727 OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
2828 OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD
2929use M_CLI2, only : set_args, lget, sget, unnamed, remaining, specified
@@ -47,6 +47,7 @@ module fpm_command_line
4747 fpm_run_settings, &
4848 fpm_test_settings, &
4949 fpm_update_settings, &
50+ fpm_clean_settings, &
5051 get_command_line_settings
5152
5253type, abstract :: fpm_cmd_settings
@@ -104,6 +105,13 @@ module fpm_command_line
104105 logical :: clean
105106end type
106107
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+
107115character (len= :),allocatable :: name
108116character (len= :),allocatable :: os_type
109117character (len= ibug),allocatable :: names(:)
@@ -113,9 +121,10 @@ module fpm_command_line
113121character (len= :), allocatable :: help_new(:), help_fpm(:), help_run(:), &
114122 & help_test(:), help_build(:), help_usage(:), help_runner(:), &
115123 & 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(:)
117126character (len= 20 ),parameter :: manual(* )= [ character (len= 20 ) :: &
118- & ' ' , ' fpm' , ' new' , ' build' , ' run' , &
127+ & ' ' , ' fpm' , ' new' , ' build' , ' run' , ' clean ' , &
119128& ' test' , ' runner' , ' install' , ' update' , ' list' , ' help' , ' version' ]
120129
121130character (len= :), allocatable :: val_runner, val_compiler, val_flag, val_cflag, val_ldflag, &
@@ -174,6 +183,8 @@ subroutine get_command_line_settings(cmd_settings)
174183 character (len= 4096 ) :: cmdarg
175184 integer :: i
176185 integer :: widest
186+ integer :: os
187+ logical :: unix
177188 type (fpm_install_settings), allocatable :: install_settings
178189 character (len= :), allocatable :: common_args, compiler_args, run_args, working_dir, &
179190 & c_compiler, archiver
@@ -184,8 +195,9 @@ subroutine get_command_line_settings(cmd_settings)
184195 type (error_t), allocatable :: error
185196
186197 call set_help()
198+ os = get_os_type()
187199 ! text for --version switch,
188- select case (get_os_type() )
200+ select case (os )
189201 case (OS_LINUX); os_type = " OS Type: Linux"
190202 case (OS_MACOS); os_type = " OS Type: macOS"
191203 case (OS_WINDOWS); os_type = " OS Type: Windows"
@@ -196,6 +208,7 @@ subroutine get_command_line_settings(cmd_settings)
196208 case (OS_UNKNOWN); os_type = " OS Type: Unknown"
197209 case default ; os_type = " OS Type: UNKNOWN"
198210 end select
211+ unix = os_is_unix(os)
199212 version_text = [character (len= 80 ) :: &
200213 & ' Version: 0.5.0, alpha' , &
201214 & ' Program: fpm(1)' , &
@@ -321,7 +334,7 @@ subroutine get_command_line_settings(cmd_settings)
321334 select case (size (unnamed))
322335 case (1 )
323336 if (lget(' backfill' ))then
324- name= ' .'
337+ name= ' .'
325338 else
326339 write (stderr,' (*(7x,g0,/))' ) &
327340 & ' <USAGE> fpm new NAME [[--lib|--src] [--app] [--test] [--example]]|[--full|--bare] [--backfill]'
@@ -424,6 +437,8 @@ subroutine get_command_line_settings(cmd_settings)
424437 help_text= [character (len= widest) :: help_text, help_help]
425438 case (' version' )
426439 help_text= [character (len= widest) :: help_text, version_text]
440+ case (' clean' )
441+ help_text= [character (len= widest) :: help_text, help_clean]
427442 case default
428443 help_text= [character (len= widest) :: help_text, &
429444 & ' <ERROR> unknown help topic "' // trim (unnamed(i))// ' "' ]
@@ -469,6 +484,7 @@ subroutine get_command_line_settings(cmd_settings)
469484 if (lget(' list' ))then
470485 call printhelp(help_list_dash)
471486 endif
487+
472488 case (' test' )
473489 call set_args(common_args // compiler_args // run_args // ' --' , &
474490 help_test,version_text)
@@ -528,6 +544,19 @@ subroutine get_command_line_settings(cmd_settings)
528544 fetch_only= lget(' fetch-only' ), verbose= lget(' verbose' ), &
529545 clean= lget(' clean' ))
530546
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+
531560 case default
532561
533562 if (which(' fpm-' // cmdarg).ne. ' ' )then
@@ -607,6 +636,7 @@ subroutine set_help()
607636 ' test Run the test programs ' , &
608637 ' update Update and manage project dependencies ' , &
609638 ' install Install project ' , &
639+ ' clean Delete the build ' , &
610640 ' ' , &
611641 ' Enter "fpm --list" for a brief list of subcommand options. Enter ' , &
612642 ' "fpm --help" or "fpm SUBCOMMAND --help" for detailed descriptions. ' , &
@@ -626,6 +656,7 @@ subroutine set_help()
626656 ' [--list] [--compiler COMPILER_NAME] [-- ARGS] ' , &
627657 ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ' , &
628658 ' [options] ' , &
659+ ' clean [--skip] [--all] ' , &
629660 ' ' ]
630661 help_usage= [character (len= 80 ) :: &
631662 ' ' ]
@@ -722,12 +753,14 @@ subroutine set_help()
722753 ' + build Compile the packages into the "build/" directory. ' , &
723754 ' + new Create a new Fortran package directory with sample files. ' , &
724755 ' + 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 ' , &
726757 ' for that release. ' , &
727758 ' + test Run the tests. ' , &
728759 ' + help Alternate to the --help switch for displaying help text. ' , &
729760 ' + 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. ' , &
731764 ' ' , &
732765 ' Their syntax is ' , &
733766 ' ' , &
@@ -743,7 +776,8 @@ subroutine set_help()
743776 ' help [NAME(s)] ' , &
744777 ' list [--list] ' , &
745778 ' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] ' , &
746- ' [options] ' , &
779+ ' [options] ' , &
780+ ' clean [--skip] [--all] ' , &
747781 ' ' , &
748782 ' SUBCOMMAND OPTIONS ' , &
749783 ' -C, --directory PATH' , &
@@ -759,6 +793,10 @@ subroutine set_help()
759793 ' the fpm(1) command this shows a brief list of subcommands.' , &
760794 ' --runner CMD Provides a command to prefix program execution paths. ' , &
761795 ' -- 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. ' , &
762800 ' ' , &
763801 ' VALID FOR ALL SUBCOMMANDS ' , &
764802 ' --help Show help text and exit ' , &
@@ -788,8 +826,8 @@ subroutine set_help()
788826 ' # my build options ' , &
789827 ' options build ' , &
790828 ' 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 ' , &
793831 ' -frecord-marker=4 -L/usr/X11R6/lib -L/usr/X11R6/lib64 -lX11" ' , &
794832 ' ' , &
795833 ' Note --flag would have to be on one line as response files do not ' , &
@@ -809,6 +847,7 @@ subroutine set_help()
809847 ' fpm new --help ' , &
810848 ' fpm run myprogram --profile release -- -x 10 -y 20 --title "my title" ' , &
811849 ' fpm install --prefix ~/.local ' , &
850+ ' fpm clean --all ' , &
812851 ' ' , &
813852 ' SEE ALSO ' , &
814853 ' ' , &
@@ -998,8 +1037,8 @@ subroutine set_help()
9981037 ' NAME ' , &
9991038 ' new(1) - the fpm(1) subcommand to initialize a new project ' , &
10001039 ' 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] ' , &
10031042 ' fpm new --help|--version ' , &
10041043 ' ' , &
10051044 ' DESCRIPTION ' , &
@@ -1219,7 +1258,22 @@ subroutine set_help()
12191258 ' ' , &
12201259 ' fpm install --prefix $PWD --bindir exe' , &
12211260 ' ' ]
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
12231277
12241278 subroutine get_char_arg (var , arg )
12251279 character (len= :), allocatable , intent (out ) :: var
0 commit comments