0382 / argparse-f

Modern Fortran command line parser, implemented with OOP.
MIT License
22 stars 1 forks source link

[feature request] Parsing the arguments included in the quotation marks #11

Open LaplaceSoda opened 1 month ago

LaplaceSoda commented 1 month ago

Description

The arguments included in the quotation marks will be regarded as one argument both in Fortran and in this module, which means that if we use temp.exe "-n 4", the function command_argument_count() will return 1 and the argparser will not parse the argument n normally but return an error Error: integer option '-n' cannot be in aggregate argument.

Expected Behaviour

The effect of the command git commit -m init is equal to git commit "-m init" is an example that shows the expected behavior.

0382 commented 1 month ago

I don't think this is a good idea. Every software treats arguments in the quotation as one argument. For example git commit -m "add some features", the last three words is one argument.

LaplaceSoda commented 1 month ago

Actually, the numbers of argument don't matter. What I mean is wondering if this module can be updated to deal with the command included in quotation like "-n 4"

0382 commented 1 month ago

The number is important, the arguments in the quotation should not be sperated, it is what every software do.

As for your problem, I think this is one side-effect of the aggregate option argument defined in thie module, since it starts with one - chacacter, so it is treated as something like -lah in ls -lah command.

If you are expected to get two arguments for "-n 4", then I think there are no software will do so.

If you are expected to get one arguments for "-n 4", then I think it is some flaw that this module cannot achieve.

LaplaceSoda commented 1 month ago

Actually what I want is to get the value of argument -n from the whole string -n 8, which is regard as one argument in Fortran's command_argument_count().

In my opinion this may seems to be more like the second situation you have mentioned.

0382 commented 1 month ago

I guess you want to do the following thing:

args%add_option_integer("-n", "--number", "something number", 1)
! ...
args%get_option_integer("-n") ! if you excepte it to return 8 when you give `-n 8` in the command line

what you should do is not put them in the quotation marks.

The quotation marks in command line are only used to include space in the argument. The typical example is the git commit -m "fix some bug", where people want to treat the last three words as one meanful argument. So do not use the quotation marks in any other case.