Closed amartinhuertas closed 4 years ago
Dear @amartinhuertas ,
thank you for your feeback. The answer is no, currently if FLAP parses an unknown CLA it raises and error. I never focused it could be helpful in scenario like your to raise only a warning (or even do nothing) when an unknown CLA is passed. I'll try to implement such a feature, but I am not sure the timing, maybe I can try to implement it during the next week.
I am thinking to add a new implicit switch (like the --help one) that disable the raising of error for unknown CLA. What do you think about such an implementation? You could have something like
type(command_line_interface) :: cli
call cli%init(ignore_unknown_clas=.true., ...)
...
Thanks for your prompt answer.
I'll try to implement such a feature, but I am not sure the timing, maybe I can try to implement it during the > next week.
Thanks so much! I am not in a hurry. I have found a way to work-around it. (let the third-party library to get CLAS from a file)
I am thinking to add a new implicit switch (like the --help one) that disable the raising of error for unknown > CLA. What do you think about such an implementation? You could have something like
type(command_line_interface) :: cli
call cli%init(ignore_unknown_clas=.true., ...) ...
That's precisely what I need.
Dear @szaghi ,
Have you been thinking about implementing this feature? I am using FLAP to parse my own clas, but i need to pass PETSc clas also...
Best regards!
@ShatrovOA
I am very sorry, I was focused into other bugs of my libraries and I forget to implement this feature.
Let me some days more.
Cheers
@ShatrovOA
I am very sorry, I was focused into other bugs of my libraries and I forget to implement this feature.
Let me some days more.
Cheers
Hi @szaghi ,
Did you forget to implement this feature once again?
Best regards!
@ShatrovOA
During this week I should find the time to try to implement this feature
Dear @amartinhuertas @ShatrovOA
I have just pushed a new version (v1.2.1) that implement this feature request. I report below the commit log:
Add ignore passed unknown CLAs, fix issue#82
The CLI can now be initialized with a flag for ignoring the passed CLAs
that are unknown. An error is still echoed, but the CLI parsing goes on
until the end without exit the flow. By default a passed unknown CLA
raises a blocking error as in the previous verions.
This change addresses the need by:
add a new option to `init` method of CLI object, e.g.
call cli%init(..., ignore_unknown_clas=.true.)
A dedicated test has been added, i.e.
`src/test/flap_test_ignore_unknown_clas.f90`
Side effects:
Nothing.
Let me know if this implementation is ok.
Cheers
Dear @szaghi
First of all thanks for your work. I have a question. My program is using MPI and my common usage of FLAP is
then on rank 0 I call parse method and bcast error flag. I call parse on purpose since I dont want to see multiple copies of some --help messages or --version messages. I noticed that I am getting non-zero error after calling parse with ignore_unknown_clas=.true..
My question is: are you planning to change one day error codes or I can safely ignore code 1004?
Great @szaghi ! Thanks so much for your work. @victorsndvg and me will test it and let you know if there is any issue with the update!
Dear @szaghi
First of all thanks for your work. I have a question. My program is using MPI and my common usage of FLAP is
- use flap
- init
- add
- add_group
- ...
then on rank 0 I call parse method and bcast error flag. I call parse on purpose since I dont want to see multiple copies of some --help messages or --version messages. I noticed that I am getting non-zero error after calling parse with ignore_unknown_clas=.true..
My question is: are you planning to change one day error codes or I can safely ignore code 1004?
Hi, this was a designed behavior: 1004 is the first error code that can be ignored because the user selected the ignore unknown clas. It is a sort of warning code. It should remain as is until you or other users request a different behavior.
Great @szaghi ! Thanks so much for your work. @victorsndvg and me will test it and let you know if there is any issue with the update!
Great, thank you guys.
Cheers
Dear @szaghi ,
I've been testing a little this new feature. Thanks for your effort!
I've seen how it works, but I would like to confirm this as the expected behaviour.
Something like that:
unknown_flags
is activated, you can pass flags that are not managed by FLAP (non-FLAP-flags).I'm right? If yes, I think point 3 must be explicitly explained anywhere in docs.
Do you agree?
Best
@victorsndvg
Yes (and not). Currently the behavior seems to be as your description, but the effect 3 is not a desired feature. When an unknown CLA is passed and the user have chosen to ignore unknown CLAs, at the first unknown CLA passed the error-warning code (1004) is triggered and an error prompted, but the CLAs parsing should go further. If a valid CLA is passed after an unknown one it must be correctly parsed, if not it is a bug. I have to check it, thank you very much for pointing it out.
@szaghi ,
thanks for your quick response. Let me know your conclusion or any further change after checking it.
@victorsndvg
I confirm, the valid CLAs passed after an unknown CLA are missed, this is a bug, I do not like to force valid CLAs being before unknown ones.
@szaghi ,
I agree with you. I would like only to ignore anything that is out of the FLAP registered flags schema, but to accept any other flag as soon as FLAP recognise them
@victorsndvg
A new release is online, with a bug fix. I'll wait for your feedback.
Cheers
@szaghi
I tested it. It seems that the unkown-flag-order issue is solved, but I've found a new one. If I call some programs using FLAP with --help
flag it crashes with segfault.
One of the programs compiled in debug mode show this error:
`` At line 1387 of file /home/sandman/Repos/gitlab/fempar/ThirdParty/FLAP/src/lib/flap_command_line_interface_t.F90 Fortran runtime error: Index '1' of dimension 1 of array 'self%clasg' above upper bound of 0
@victorsndvg Sorry for the delay, I has been sick in the last days (my little daughter shared with me a virus...).
In the new version there is a fix (it seems that the invocation of help usage message was always bugged, but only the last version raised this). Let me know if the fix works.
Cheers
Dear @szaghi
I modified your example and --help, --version switches don't work for me at all:
program flap_test_ignore_unknown_clas
use flap, only : command_line_interface, ERROR_UNKNOWN_CLAS_IGNORED
use penf
implicit none
type(command_line_interface) :: cli !< Command Line Interface (CLI).
character(99) :: a_string !< String value.
integer(I4P) :: error !< Error trapping flag.
call cli%init(description = 'ignore unknown CLAs usage FLAP example', ignore_unknown_clas=.true.)
call cli%add(switch='--string', switch_ab='-s', help='a string', required=.false., act='store', def = 'asdf', error=error)
call cli%add_group(group='restart', description='Enables Restart')
call cli%add( group='restart', &
switch='--number', &
switch_ab='-n', &
help='Set number of restart file', &
help_color='red', &
help_style='italics_on', &
required=.true., &
def = '-1', &
act='store')
call cli%add_group(group='converter', description='Switch to Converter mode')
call cli%add( group = 'converter', &
switch='--start', &
switch_ab='-s', &
help='Set initial file number that should be converted', &
help_color='cyan', &
help_style='italics_on', &
required=.true., &
def = '-1', &
act='store')
call cli%get(switch='-s', val=a_string, error=error)
! if (error /= ERROR_UNKNOWN_CLAS_IGNORED) stop
print '(A)', cli%progname//' has been called with the following argument:'
print '(A)', 'String = '//trim(adjustl(a_string))
print '(A,I5)', 'Error code = ', error
endprogram flap_test_ignore_unknown_clas
Best regards!
Dear @ShatrovOA thank you for your feedback, but I do not understand the error you faced: do you mean that with your modified example the help message is not printed?
Dear @ShatrovOA thank you for your feedback, but I do not understand the error you faced: do you mean that with your modified example the help message is not printed?
I noticed that in my case program ignores --help flag and continues execution.
@ShatrovOA
I verified, something strange happens with groups... I am try to fix this new bug
@ShatrovOA
I have just uploaded a new version with a fix, let me know if it works
Dear @szaghi ,
Everything works for me now.
Thank you!
@ShatrovOA you are welcome and thank you for your feedback.
@victorsndvg I am closing this issue, but feel free to re-open it if needed.
Cheers.
Sorry for the late response,
everything is working fine for us now.
Hope you are getting better @szaghi !
Thanks for your work.
Best
@victorsndvg Thank you victor!
I am getting better, but slowly...
Cheers
Dear @szagui,
In my application, I have a subset of CLAs that have to be parsed by FLAP, and another subset of CLAs that have to be parsed by a third party library I am calling from my application. Is there anyway to set up FLAP such that unknown CLA names are just ignored when parsing? In this case, the FLAP main data structure should be in the same status as this unkown CLA names were not passed. In case this is not possible, how can FLAP be modified such that this is possible on demand?
Thanks in advance for your help! Best regards, @amartinhuertas.