szaghi / FLAP

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

In an array type switch, 'def' is not correctly parsed #103

Closed GHNewbiee closed 1 year ago

GHNewbiee commented 1 year ago

When a switch is a type of array, then def value should be an array, too. For the time being, only the first element is considered, which is not right; unless I miss something. Tia

Example

call cli%add(                    &
  switch     = '--display',      &
  switch_ab  = '-dis',           &
  help       = '...',            &
  help_color = 'cyan',           &
  help_style = 'bold_on',        &
  required   = .false.,          &
  act        = 'store',          &
  nargs      = '+',              &
  def        = '1,2,4,40,21,25', &
  choices    = '...'             &
)

call cli%get_varying(switch='-dis', val=display, error=error)

print *, size(display), display !< prints 1 1
GHNewbiee commented 1 year ago

Sorry, 'display' definitely is an array. It's just of size 1, because (I suspect) def string is not parsed in a correct manner. Ta

szaghi commented 1 year ago

Hi,

As a design choice, I decided that the default value (as well as the value passed by command line, if any) is always as a string, no matter of what it is really (scalar, array, real, integer...). When the user invokes any "get" method, the string is casted to the correct type/rank.

In your example I think that the problem is due to the array values separator: by default it is a white space, not a comma. Indeed, it should be customizable, but the documentation is poor, my bad.

I'll try to update the documentation soon, I have introduced new important features in the incoming release.

Kind regards

GHNewbiee commented 1 year ago

Oh, ok then. Thanks for the tip. There is a test (flap_test_basic) where the use of white space is clear. It's oversight from my side. Sorry!

Many thanks and kind regards, too