Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support common '--' notation #13

Open
wernight opened this issue May 1, 2012 · 6 comments
Open

Support common '--' notation #13

wernight opened this issue May 1, 2012 · 6 comments

Comments

@wernight
Copy link
Contributor

wernight commented May 1, 2012

Having '-help' isn't common, it should mean '-h -e -l -p' wereas '--help' should be the long form.

@adrianaisemberg
Copy link
Owner

True. This isn't common, however, changing this will not only break existing code (which may be acceptable in some cases, using the [Obsolete] attribute for example), it will break existing apps. Breaking existing apps affects users of the app instead of developers and this is not acceptable.
For example, if one has a script with the following lines:

myexe login -user=john -pass=foobar

Unless a developer updates the myexe code, the script will no longer work.

Thanks for the suggestion. I may consider a "CLAP2" and have this supported.

@wernight
Copy link
Contributor Author

wernight commented May 2, 2012

I agree. First I forgot another benefit: The arguments end market: mycmd --foo foo -- --this-is-a-file -another-one

There are still solutions:

  1. Flag to support "-help" => "-h -e -l -p"
  2. Major version with clear backward incompatible changes (much cleaner).

@adrianaisemberg
Copy link
Owner

Can you please elaborate more on the "end market" you mentioned?
I'm not sure I understand this line:
mycmd --foo foo -- --this-is-a-file -another-one

@wernight
Copy link
Contributor Author

wernight commented May 2, 2012

Everything after a " -- " will never be interpreted as a named parameter. Other than that, it has no effect.

For example both are equivalent:

mycmd --arg1 ok foo-file bar-file 
mycmd --arg1 ok -- foo-file bar-file 

It's useful when you want to make sure that file names that possibly start by "-" or "--" will not be interpreted as optional parameter values. For example this is different

mycmd --arg1 ok --arg1      # Interpreted as argument named "arg1"
mycmd --arg1 ok -- --arg1   # Interpreted as unnamed argument "--arg1"

It might not seem that useful at first but for example I use msysgit on Windows. Meaning I can call: find ... | xargs mycmd -arg1 ok -- which would be safer.

NDesk.Options supports that notation.

@alexanderfast
Copy link

I would also like to see this.

Or rather the full GNU style standard since I'm porting some Unix based tools to .Net and need to follow that convention. But I'm putting this here rather than creating a new issue. The minimum would be:

--long-option   # for long option names
-s              # for short option names
-abc            # for multiple short options without arguments (one character per option)
-s arg          # short option with argument
--long arg      # long option with argument

I found this project when looking for a verb based parser since I also need to be able to do something like git or mercurial:

git [verb] [verb specific options]

If you want, you could check the gnu getopt documentation although I personally find the POSIX specification a bit easier to digest.

You have some great code going on here. Maybe it would be enough to create an alternate parser with different rules. Besides, the default behavior can remain totally the same so no implementations are broken.

Would you be interested in any contributions regarding this?

@adrianaisemberg
Copy link
Owner

It was a long time since my last contribution to the project. I actually considered it "done" (only bug fixing).
Answering your question - yes, I would very much be interested in any contributions.

Thanks,
Adrian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants