Skip to content

Commit

Permalink
Merge pull request #62 from zbeekman/error-help-unit-specify
Browse files Browse the repository at this point in the history
Fixes #61: More output control
  • Loading branch information
szaghi committed Apr 8, 2016
2 parents af963b9 + 06da04f commit 414e265
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/lib/flap_command_line_argument_t.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module flap_command_line_argument_t
!-----------------------------------------------------------------------------------------------------------------------------------
!< Command Line Argument (CLA) class.
!-----------------------------------------------------------------------------------------------------------------------------------
use, intrinsic:: ISO_FORTRAN_ENV, only : stderr=>ERROR_UNIT
use flap_object_t, only : object
use flap_utils_m
use penf
Expand Down
3 changes: 1 addition & 2 deletions src/lib/flap_command_line_arguments_group_t.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module flap_command_line_arguments_group_t
!-----------------------------------------------------------------------------------------------------------------------------------
!< Command Line Arguments Group (CLAsG) class.
!-----------------------------------------------------------------------------------------------------------------------------------
use, intrinsic:: ISO_FORTRAN_ENV, only: stdout=>OUTPUT_UNIT, stderr=>ERROR_UNIT
use flap_command_line_argument_t, only : command_line_argument, &
ACTION_PRINT_HELP, &
ACTION_PRINT_VERS, &
Expand Down Expand Up @@ -141,7 +140,7 @@ subroutine is_required_passed(self, pref)
do a=1, self%Na
if (.not.self%cla(a)%is_required_passed(pref=pref)) then
self%error = self%cla(a)%error
write(stdout, '(A)') self%usage(pref=pref)
write(self%usage_lun, '(A)') self%usage(pref=pref)
return
endif
enddo
Expand Down
16 changes: 11 additions & 5 deletions src/lib/flap_command_line_interface_t.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module flap_command_line_interface_t
!-----------------------------------------------------------------------------------------------------------------------------------
!< Command Line Interface (CLI) class.
!-----------------------------------------------------------------------------------------------------------------------------------
use, intrinsic:: ISO_FORTRAN_ENV, only: stdout=>OUTPUT_UNIT, stderr=>ERROR_UNIT
use flap_command_line_argument_t, only : command_line_argument, action_store
use flap_command_line_arguments_group_t, only : command_line_arguments_group, STATUS_PRINT_H, STATUS_PRINT_V
use flap_object_t, only : object
Expand Down Expand Up @@ -121,7 +120,8 @@ elemental subroutine free(self)
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine free

subroutine init(self, progname, version, help, description, license, authors, examples, epilog, disable_hv)
subroutine init(self, progname, version, help, description, license, authors, examples, epilog, disable_hv, &
usage_lun, error_lun, version_lun)
!---------------------------------------------------------------------------------------------------------------------------------
!< Initialize CLI.
!---------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -135,13 +135,19 @@ subroutine init(self, progname, version, help, description, license, authors, ex
character(*), optional, intent(in) :: examples(1:) !< Examples of correct usage.
character(*), optional, intent(in) :: epilog !< Epilog message.
logical, optional, intent(in) :: disable_hv !< Disable automatic insert of 'help' and 'version' CLAs.
integer(I4P), optional, intent(in) :: usage_lun !< Unit number to print usage/help
integer(I4P), optional, intent(in) :: version_lun !< Unit number to print version/license info
integer(I4P), optional, intent(in) :: error_lun !< Unit number to print error info
character(len=:), allocatable :: prog_invocation !< Complete program invocation.
integer(I4P) :: invocation_length !< Length of invocation.
integer(I4P) :: retrieval_status !< Retrieval status.
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
call self%free
if (present(usage_lun)) self%usage_lun = usage_lun
if (present(version_lun)) self%version_lun = version_lun
if (present(error_lun)) self%error_lun = error_lun
if (present(progname)) then
self%progname = progname
else
Expand Down Expand Up @@ -578,7 +584,7 @@ subroutine parse(self, pref, args, error)
call self%print_version(pref=pref)
stop
elseif (self%error == STATUS_PRINT_H) then
write(stdout,'(A)') self%usage(pref=pref, g=g)
write(self%usage_lun,'(A)') self%usage(pref=pref, g=g)
stop
endif

Expand Down Expand Up @@ -1534,7 +1540,7 @@ subroutine print_usage(self, pref)
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
write(stdout, '(A)') self%usage(pref=pref, g=0)
write(self%usage_lun, '(A)') self%usage(pref=pref, g=0)
return
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine print_usage
Expand Down Expand Up @@ -1630,7 +1636,7 @@ subroutine errored(self, error, pref, group, switch)
! self%error_message = prefd//self%progname//': error: too few arguments ('//trim(str(.true.,Na))//')'//&
! ' respect the required ('//trim(str(.true.,self%Na_required))//')'
endselect
write(stderr,'(A)')
write(self%error_lun,'(A)')
call self%print_error_message
endif
return
Expand Down
33 changes: 18 additions & 15 deletions src/lib/flap_object_t.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ module flap_object_t
type, abstract, public :: object
!< Base (abstract) class upon which FLAP's concrete classes are built.
private
character(len=:), public, allocatable :: progname !< Program name.
character(len=:), public, allocatable :: version !< Program version.
character(len=:), public, allocatable :: help !< Help message.
character(len=:), public, allocatable :: description !< Detailed description.
character(len=:), public, allocatable :: license !< License description.
character(len=:), public, allocatable :: authors !< Authors list.
character(len=:), public, allocatable :: epilog !< Epilogue message.
character(len=:), public, allocatable :: m_exclude !< Mutually exclude other CLA(s group).
character(len=:), public, allocatable :: error_message !< Meaningful error message to standard-error.
integer(I4P), public :: error=0_I4P !< Error trapping flag.
character(len=:), public, allocatable :: progname !< Program name.
character(len=:), public, allocatable :: version !< Program version.
character(len=:), public, allocatable :: help !< Help message.
character(len=:), public, allocatable :: description !< Detailed description.
character(len=:), public, allocatable :: license !< License description.
character(len=:), public, allocatable :: authors !< Authors list.
character(len=:), public, allocatable :: epilog !< Epilogue message.
character(len=:), public, allocatable :: m_exclude !< Mutually exclude other CLA(s group).
character(len=:), public, allocatable :: error_message !< Meaningful error message to standard-error.
integer(I4P), public :: error=0_I4P !< Error trapping flag.
integer(I4P), public :: usage_lun=stderr !< Output unit to print help/usage messages
integer(I4P), public :: version_lun=stdout !< Output unit to print version message
integer(I4P), public :: error_lun=stderr !< Error unit to print error messages
contains
procedure :: free_object !< Free dynamic memory.
procedure :: print_version !< Print version.
Expand Down Expand Up @@ -68,12 +71,12 @@ subroutine print_version(self, pref)

!---------------------------------------------------------------------------------------------------------------------------------
prefd = '' ; if (present(pref)) prefd = pref
write(stdout,'(A)')prefd//self%progname//' version '//self%version
write(self%version_lun,'(A)')prefd//self%progname//' version '//self%version
if (self%license /= '') then
write(stdout,'(A)')prefd//self%license
write(self%version_lun,'(A)')prefd//self%license
endif
if (self%authors /= '') then
write(stdout,'(A)')prefd//self%authors
write(self%version_lun,'(A)')prefd//self%authors
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -87,8 +90,8 @@ subroutine print_error_message(self)
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
write(stderr, '(A)') self%error_message
write(stderr, '(A)')
write(self%error_lun, '(A)') self%error_message
write(self%error_lun, '(A)')
return
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine print_error_message
Expand Down

0 comments on commit 414e265

Please sign in to comment.