szaghi / FLAP

Fortran command Line Arguments Parser for poor people
151 stars 34 forks source link

gfortran5 possible class(*) issue #37

Closed zbeekman closed 9 years ago

zbeekman commented 9 years ago

Hi @szaghi have you tried running the Test_Driver program with the --man_file argument, but letting it try to use the default value?

$ ./Test_Driver/Test_Driver -s test --man_file
Test_Driver has been called with the following arguments values:
String              input = test
Real                input = +0.100000000000000E+001
Integer             input = +1
Exclusive   integer input = -1
Environment integer input = -1
Boolean             input = F
Valued boolean      input = T
Positional real     input = +0.100000000000000E+001
Integer list inputs:
Input(1) = +1
Input(2) = +8
Input(3) = +32
Saving man page to ��
At line 2399 of file src/Data_Type_Command_Line_Interface.F90
Fortran runtime error: Cannot open file ‘’: No such file or directory

I modified one of the last lines of the Test_Driver source to also print the value being returned by cli%get(switch='--man_file'…) and as you can see, there is a problem returning the default value which is listed as Test_Driver.1

zbeekman commented 9 years ago

Weird… I don’t have anymore time to work on figuring this out today. I think maybe it is related to this: http://stackoverflow.com/questions/23995529/select-type-with-unlimited-polymorphic-pointer-to-character-variable

szaghi commented 9 years ago

Hi @zbeekman thank you for the test. I have not yet tested with gfortran5 (I think). I will fix it the next week.

zbeekman commented 9 years ago

Have you tried doing this with 4.9? The problem may be present there too… I’m not sure. Have a good weekend!

szaghi commented 9 years ago

Yes, on travis all tests should work, also the man page Generation. Maybe the problem is into the default value (that i think is not tested in travis).

Have a good week, I am going to "sleep" with Angelica ... crying

szaghi commented 9 years ago

Yes, on travis test is done with explicit name not the default value https://github.com/szaghi/FLAP/blob/master/fobos#L288

zbeekman commented 9 years ago

yes the tests don’t try to use the default value for strings AFAICT. Good luck getting some sleep.

zbeekman commented 9 years ago

this seems like it might be fixed from the latest round of commits… still investigating…

zbeekman commented 9 years ago

OK… I think the source of this bug might be me! I was under the impression that I could specify --man_file without giving it an argument, and that the default value would be used. But it appears that the default value is only used when the switch is not passed at all.

Often UNIX programs will have switches that can be passed without any arguments causing them to enable a certain behavior or feature with some default value. If the switch is passed with an argument then the argument overrides the default. In the case where the CLA is actually just the null string (e.g., my_prog --switch_optional_arg --some_other_switch vs my_prog --switch_optional_arg 'foo’ --some_other_switch) rather than overwriting the default value with the null string, you just keep the default value. Maybe you need to add another 'action' to cli%add to say store_if_not_null or something like that…

szaghi commented 9 years ago

@zbeekman

Yesterday I saw that, but your firdt guess was rigth: for this specific case it should work as you supposed, namely if you pass --man_file without value the default one must be used. As soon as I arrive to office I fix this bug. Thank you for finding it!

szaghi commented 9 years ago

Fixed.

I have introduced a new action: action='store*'. If it is set, the named option can be invoked also without a value and in this case the value is retrieved by the default one. Note that if the default is not set errors can occur when invoking the get method. Some special rules holds for store*, see https://github.com/szaghi/FLAP/wiki/CLI-Method-add.

Now the Test_Driver works as expected: if --man_page is passed without a file name it is saved on Test_Driver.1 that is the default value.

I am closing this issue, but open a new one if this feature is bugged or not conforming your request.

zbeekman commented 9 years ago

so, just to clarify… action='store*' is required/mandatory to be able to use options like --man_file without passing an additional argument?

i.e.,

call cli%add(switch='--man_file',act='store*',def='Test_Driver.1',required=.false.,help='help string')

when called as Test_Driver/Test_driver --man_file will produce Test_Driver.1 BUT

call cli%add(switch='--man_file',act='store',def='Test_Driver.1',required=.false.,help='help string') 

will produce an error if called the same way: Test_Driver/Test_driver —man_file?

szaghi commented 9 years ago

@zbeekman yes.

I am running away... see you tomorrow!