Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing lots of unknown CLAs before known ones #110

Open
ShatrovOA opened this issue Mar 9, 2024 · 1 comment
Open

Passing lots of unknown CLAs before known ones #110

ShatrovOA opened this issue Mar 9, 2024 · 1 comment
Assignees

Comments

@ShatrovOA
Copy link
Contributor

Dear @szaghi

I believe something strange is happening when passing known and unknown arguments together.

I believe that problem is located in flap_command_line_arguments_group_t.f90 lines 412-421. I may be wrong...

Consider following simple program

program flap_test_basic
use iso_fortran_env, only: output_unit
use flap, only : command_line_interface
use penf

implicit none
type(command_line_interface) :: cli          !< Command Line Interface (CLI).
integer(I4P) :: val

  val = -1
  call cli%init(ignore_unknown_clas=.true., disable_hv=.true.)
  call cli%add(switch='--integer',switch_ab='-i',required=.false.,def='-2',act='store')
  call cli%parse()
  if(cli%is_passed(switch='-i')) then
    write(output_unit, '(a)') "switch='-i' is passed"
    call cli%get(val=val, switch='-i')
  endif
  call cli%free()
  write(output_unit, '(a, i0)') "integer = ",val
endprogram flap_test_basic

Running it while passing arguments in different order produces different results.
Passing known argument first:

./flap_test_basic -i 2 -s asd -ss qwe
./flap_test_basic: error: switch "-s" is unknown!

switch='-i' is passed
integer = 2

Somehow nothing is said about unknown arguments asd, -ss and qwe
But integer value is getting extracted correctly

Next, passing known argument second:

./flap_test_basic -s asd -i 2 -ss qwe
./flap_test_basic: error: switch "-s" is unknown!

./flap_test_basic: error: switch "asd" is unknown!

./flap_test_basic: error: switch "-ss" is unknown!

switch='-i' is passed
integer = 2

In this example we are only missing ./flap_test_basic: error: switch "qwe" is unknown! error message
Once again, known integer value is getting extracted correctly

Finally, passing known argument last:

./flap_test_basic -s asd -ss qwe -i 2
./flap_test_basic: error: switch "-s" is unknown!

./flap_test_basic: error: switch "asd" is unknown!

./flap_test_basic: error: switch "-ss" is unknown!

integer = -1

Known argument is not getting extracted at all. cli%is_passed(switch='-i') returns False.

@szaghi
Copy link
Owner

szaghi commented Mar 10, 2024

@ShatrovOA Thank you very much for pointing it out. I'll try to fix this bug ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants