getopt_port icon indicating copy to clipboard operation
getopt_port copied to clipboard

Missing optional_argument support

Open apanloco opened this issue 6 years ago • 4 comments

Hey!

It looks like optional_argument "has_arg" flag is not yet implemented. Is this intentional? Will it come?

Thanks!

apanloco avatar Dec 27 '17 08:12 apanloco

Interesting! I thought I'd implemented everything, but this must have slipped through.

Would you be willing to take a stab at it? I can't promise when I'll get around to it (if ever).

I've been trying to keep getopt_port compatible with as many other getopt implementation as possible (with BSD and GNU as the primary inspirations).

kimgr avatar Dec 27 '17 14:12 kimgr

@apanloco Actually, I went to the test suite for verification, and I see at least a few optional_argument tests. Can you be more specific as to what's not working?

kimgr avatar Dec 28 '17 15:12 kimgr

I'll try to be more specific, but this is from memory since I've long moved passed this. (Was in a hurry, switched libs).

My app uses optional, required and positional arguments.

What I noticed was that when I used an optional requirement, followed by a required argument, followed by positional arguments, it stopped parse after the optional requirement and everything after the optional argument was put into positional arguments.

I.e. something like: --optional --required value positional

Everything including --required was put into positional.

It was something like this, but memory has already faded.

I then went on and did a search in the code for optional_argument and didn't find anything. I might have mistyped?

Thanks

apanloco avatar Dec 28 '17 17:12 apanloco

Thank you. I can see how that case might be problematic.

And yes, I was also confused that there was no handling of optional_argument, but it probably falls through for the normal cases -- the test suite at least proves it exists :)

I'll take a look at this when I find some time.

kimgr avatar Dec 28 '17 21:12 kimgr

I added a test case for this in https://github.com/kimgr/getopt_port/pull/8, not sure if it reflects what you ran into originally (probably not!). Let's close this bug.

kimgr avatar Jun 24 '23 13:06 kimgr