Cygwin argument handling?

Wednesday 4 August 2004This is more than 20 years old. Be careful.

So, I love cygwin, because it gives me powerful Unix command line tools for my Windows machine. Thank you. I love it. But: would it kill them to accept -? as a request for help?

$ diff -?
diff: invalid option -- ?
diff: Try `diff --help' for more information.

Why? What would be so terrible about understanding dash-query? I type it every time I want help, and have to look at that stupid error message every time. Grr...

Comments

[gravatar]
If you used -? it could be interpreted as a pattern for glob expansion. If you had one or more matching filenames, like -a, the -? would be replaced by the filenames which might be other options for the program. Maybe that's unlikely, but in some shells (eg Bash with the nullglob option set), if a pattern doesn't match it'll be removed completely, so the program wouldn't know you were even trying to use an option.

To get round this you'd have to quote or escape the -? as '-?' or -\?, which you'd probably keep forgetting to do. It'd get really annoying.
[gravatar]
OK, that explains the cultural reason why -? is not a good help option. But it wouldn't hurt to accept it as well. In shells that ate question marks, it wouldn't work, and you'd need to use --help as you do today.

But on shells that didn't eat question marks (like DOS, and cygwin is designed to work with DOS), it would make the utilities that much user friendlier.

Why be dogmatic?
[gravatar]
I have a feeling the Cygwin developers imagine their audience as being primarily Unix refugees: seeing their role as providing a bridge for Unix users to be comfortable with Windows, rather than the other way around.
[gravatar]
I agree with Charles, Cygwin was designed to make Windows feel like Unix. A Unix developer wouldn't expect -? to do anything special. That said, it's an open source project, not a vendor. If you feel strongly enough maybe you'd be willing to contribute to the effort to make Cygwin an comfortable way for Windows developers to become comfortable with Unix commands?
[gravatar]
It's actually not Cygwin's fault, or even something Cygwin could reasonably fix. Cygwin just provides a translation layer between the user programs and the Windows API. The actual programs you're running (which are responsible for the command line parameters they accept) are compiled from the same sources that run on any old Unix of choice. So diff doesn't support '-?' on cygwin because it's the same code that gets built on any other platform (GNU diffutils, or fileutils, or what have you).

Your confusion probably stems from the fact that most of the standard utilities have a common set of traits, so you reasonably assume those traits come from a single source, and that it might be Cygwin, when in fact the source is just the crushing deadweight of decades of Unixy/GNUish force of habit, from under which computing might never extract itself.
[gravatar]
cygwin is just a thunking layer and a feed of programs compiled against the thunking layer. They don't maintain forks of all the commands and thus can't add -? handling.

They could maintain forks of the shells and add in -? -> --help translation, but I think that'd be a lot of work and wouldn't work for all commands anyhow.

You could download the bash source and add in the support yourself. I think that's your best bet.
[gravatar]
Andy and Will: Good points. I'd forgotten the details of how the Cygwin stuff was built.
[gravatar]
I'd bet you could use the "complete" feature to cause bash to expand -? to --help in the appropriate context, and then put it in your .bashrc or whatever (and then you could have it work for you on unix too :-) No code needed.

Note also that "make windows feel like unix" was a secondary concern - we built Cygwin specifically so that *gcc and gdb* could easily run hosted on Windows (for embedded targets, not native code.) The rest was a side effect - not necessarily a good one, as it has caused people to continue using windows in some cases - and some of the more exotic things (like pty support) were external contributions. (Every so often I see people who go from windows to cygwin and then to unix from there, which makes up for it :-)
[gravatar]
Right: cygwin isn't the source of the argument handling, and I shouldn't have identiifed it as such: it's the GNU code, or the POSIX conventions, or whatever. I don't care. Whatever it is, make -? bring up the help. So what if on Unix that argument would never get through. That just means it's safe to interpret it as help everywhere. If you can't type it easily, what's the harm? On the platforms where you can type it easily, it will be useful.
[gravatar]
Yeah, it'd be nice if everything had the same interface, but I disagree everything should adopt the DOS command line conventions. The GNU conventions are just fine and easier to understand.

Regardless, if you really want to fix your problem, you're better off making modifications to bash or whatever shell you use and rolling your own version. If you know c it should be pretty easy to do.
[gravatar]
I'm a little mystified at the resistance here: I'm not suggesting that --help stop working. I'm just suggesting adding -? to the variety of ways to get help.

Bob's suggestion above is a good one: I should look into adding the -? support myself and contributing it back.
[gravatar]
Well, my resistance isn't hard to understand. I don't think "-?" is obvious at all in terms of what to expect it to do. Thus I don't think it's a good thing to add. It's just my opinions. There's nothing wrong with having a point of view on this. My opinion doesn't make yours wrong or anything.

In regards to Bob's suggestion, I'm a little confused. Are you suggesting you're going to add -? handling to all the GNU command line tools or just to diff?

I really think you're better off adding it to your shell--that's really much easier effort-wise. Otherwise you're going to have your forks of a thousand command line tools rather than a fork of one shell.

I'm only mentioning this because I've been following your blog and you're a nice guy with a real problem that I sympathize with. If you want, I can look into the bash shell adjustment. I think that's the cygwin default shell.

I really do understand your frustration with not having -?. It drives me crazy when I'm in MS Word and vim commands don't work. I've been working in vim so long that it's the way I think. It really disrupts my thinking when Word flips out on me because I'm typing weird vim stuff.
[gravatar]
I wasn't proposing to fork anything. I was proposing to trace these command line tools back to their source (cygwin, GNU, Stallman's bedroom closet, whatever), and contribute changes to have them once and for all recognize -? as a request for help. Perhaps it's an uphill battle, and perhaps I'm being naive, but I still think it is a good change.

BTW: I don't use bash or any other advanced shell. I use the DOS command window, so getting it to do something different is out of the question.
[gravatar]
If you are using bash, why not use alias's?

I don't think you can have an alias after a command, you can only alias commands.. but, if you only use 10 or 12 commands, it would be pretty easy to do it like this:

alias -- ls-?="ls --help"
alias -- cd-?="cd --help"

So you lose the space in between command and -?, but you get to use your preferred method of -? seamlessly.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.