libre-man / unix-opts

Unix-style command line options parser
MIT License
107 stars 13 forks source link

get-opts uses argv when nil is explicitly passed as argument #30

Closed travv0 closed 3 years ago

travv0 commented 3 years ago

This seems to not match up with the behavior described in its docstring which states:

If OPTIONS is given, it should be a list to parse. If it's not given, the function will use `argv' function to get list of command line arguments.

This led me to believe that argv would only be used when the optional argument wasn't passed, not when nil was passed as the optional argument.

I can submit a pull request if you'd like, but I wanted to get your thoughts first since this change would potentially be breaking.

libre-man commented 3 years ago

I agree that this wording is a bit unfortunate, and that changing it would be better. But as versioning in common lisp is not really that common I think that a breaking change would not be the best solution, but instead rewording it is better. I understand that it is really annoying that you cannot pass an empty list to the method, so we would have to think of workaround for that.

travv0 commented 3 years ago

Yeah, I figured you'd want to play it safe but I figured I'd ask. Once I figured out the issue I was having, it was easy enough to do (when args (opts:get-opts args)) as a workaround since if you're wanting to give it an empty list, you're expecting back an empty list.

libre-man commented 3 years ago

I think a form of helper function would be nice, so that any default arguments can still be parsed. Something like a special (defun possibly-empty (args) (if args args 'empty-list).

travv0 commented 3 years ago

You mean to be used like (opts:get-opts (possibly-empty args))?

travv0 commented 3 years ago

Maybe a keyword argument for specifying how an empty list/nil should be handled would be more idiomatic?

libre-man commented 3 years ago

Sorry for my absence, but when looking at the code it seems like we already do this, when options is supplied it is used, even when it is nil. So I'm not entirely sure what is happening.

travv0 commented 3 years ago

You're sure right, at the time I made this issue I was accidentally using an older version that was cloned by another project's makefile, but I see it's been fixed since. Sorry about that!