urbanjost / M_CLI2

Fortran commandline-interface using a simple prototype command
The Unlicense
20 stars 4 forks source link

Remove `allocatable` attributes of `help_text`, `version_text` arguments in `set_args` subroutine? #10

Closed zoziha closed 2 years ago

zoziha commented 2 years ago

First of all, thank you @urbanjost for writing this library, it's very cool.

In the process of using the M_CLI2 library, I found that the allocatable attributes of help_text and version_text do not seem to be so necessary.

Removing the allocatable attributes makes the set_args interface more lenient, allowing the user to enter an array of constant strings (character(*), parameter :: help_text(*) = [...]). I made such a modification (a commit), and it looks like there are no apparent issues.

program main

    use M_CLI2
    character(*), parameter :: help_text(*) = [character(10) :: "help1", "help2"]
    character(:), allocatable :: version_text(:)

    version_text = [character(10) :: "version1", "version2"]
    call set_args("", help_text, version_text)

end program main

Before:

>> fpm run -- --help
M_CLI2.F90                             done.
libdemo.a                              done.
main.f90                               failed.
[  75%]Compiling...
app\main.f90:8:22:

    8 |     call set_args("", help_text, version_text)
      |                      1
Error: Actual argument at (1) to allocatable or pointer dummy argument 'help_text' must have a deferred length type parameter if 
and only if the dummy has one
<ERROR> Compilation failed for object " app_main.f90.o "
<ERROR>stopping due to failed compilation
STOP 1

After:

>> fpm run -- --help
M_CLI2.F90                             done.
libdemo.a                              done.
main.f90                               done.
demo.exe                               done.
[100%] Project compiled successfully.
help1
help2
urbanjost commented 2 years ago

Had a little trouble with the github merge, but it appears to have worked this time. This makes M_CLI2 usage more general, which is a main focus of the package. Thanks!