Skip to content

Commit

Permalink
Fix selection problems
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi authored Apr 7, 2024
1 parent 63d79da commit 629f774
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 82 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ systems.
- integration with the `fpm <https://fpm.fortran-lang.org/>`_, `CMake
<https://cmake.org/>`_ and `Meson <https://mesonbuild.com/>`_ build systems.

Detailed **documentation** is available on the `Fortuno documentation
**Documentation** is available on the `Fortuno documentation
<https://fortuno.readthedocs.io>`_ page. You can also have a look at the
examples in the `example folder <example/>`_.

Expand Down
34 changes: 24 additions & 10 deletions src/fortuno/argumentparser.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ module fortuno_argumentparser
end type argument_value


! Workaround:gfortran:13.2
! Needs user defined structure constructor to deal with class(*) field
interface argument_value
module procedure new_argument_value
end interface


!> Collection of all argument values obtained after command line had been prased
type :: argument_values
private
Expand Down Expand Up @@ -174,7 +181,7 @@ subroutine argument_parser_parse_args(this, argumentvalues, logger, exitcode)
if (matches) then
select case (argdef%argtype)
case (argtypes%bool)
argumentvalues%argvals = [argumentvalues%argvals, argument_value(name=argdef%name)]
argumentvalues%argvals = [argumentvalues%argvals, argument_value(argdef%name)]
case default
call logger%log_error("Unknown argument type")
exitcode = 1
Expand All @@ -194,15 +201,8 @@ subroutine argument_parser_parse_args(this, argumentvalues, logger, exitcode)
associate (argdef => this%argdefs(nargdefs))
! If the last argdef was not an option, store all position arguments under this name
if (.not. allocated(argdef%longopt) .and. argdef%shortopt == "") then
! argumentvalues%argvals = [argumentvalues%argvals,&
! & argument_value(name=argdef%name, argval=string_list(posargs))]
! Workaround:gfortran:13.2
block
class(*), allocatable :: tmp
tmp = string_list(posargs)
argumentvalues%argvals = [argumentvalues%argvals,&
& argument_value(name=argdef%name, argval=tmp)]
end block
argumentvalues%argvals = [argumentvalues%argvals,&
& argument_value(argdef%name, argval=string_list(posargs))]
else if (size(posargs) > 1) then
call logger%log_error("Superfluous positional arguments found")
exitcode = 1
Expand Down Expand Up @@ -270,6 +270,20 @@ subroutine argument_values_get_value_stringlist(this, name, val)
end subroutine argument_values_get_value_stringlist


!> User defined structure constructor for argument_value
function new_argument_value(name, argval) result(this)
character(*), intent(in) :: name
class(*), optional, intent(in) :: argval
type(argument_value) :: this

this%name = name
if (present(argval)) then
allocate(this%argval, source=argval)
end if

end function new_argument_value


!! Returns the command line arguments as an array of strings.
subroutine get_command_line_args_(cmdargs)
type(string), allocatable :: cmdargs(:)
Expand Down
Loading

0 comments on commit 629f774

Please sign in to comment.