akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
604 stars 62 forks source link

Combining a shorthand arguments with a parameter with flags #45

Closed goofinator closed 4 years ago

goofinator commented 4 years ago

Hello! Interesting: how critical is the design requirement: "Shorthand arguments ONLY for parser.Flag () can be combined into single argument same as ps -aux or rm -rf" It seems to me that it would be a good idea to give the opportunity to combine a shorthand arguments with a parameter with flags if it is written after them. I mean some thing like this: tar -cvaf foo.tar.gz foo

akamensky commented 4 years ago

Yes, BSD and POSIX implementations often allow for this, however I feel this makes it hard to read/understand for newcomers. Also the logic for parsing becomes very complex because of:

  1. Does it allow only 1 non-flag or multiple?
  2. If multiple how to deal with ordering?
  3. If only 1 -- how to detect it amongst other flags?
  4. etc

While answer to those may seem obvious to any experienced tar user (for example), I feel that implementing this, and documenting brings new level of complexity that I would like to avoid.

The goal of this library is to be as explicit about all options as possible and even combining shorthand arguments is already a little bit too much.

goofinator commented 4 years ago

The standard approach is a one shortened argument with a parameter that closes the sequence of flags. And I think that it is not so difficult to implement (I would take it). It seems to me that for the UNIX CLI users this is the expected behavior. And in my programs I would prefer to provide it. What if you let the programmer to enable this behavior by configuration function call, or something like that. Then the default behavior of the library will correspond to your vision, but it will be more democratic to the developer of the final application? Of course, I respect the opinion of the author, so the final decision is yours.

akamensky commented 4 years ago

I’m okay if that could be implemented with minimal changes and not affecting functionality of other methods.