Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> IMO, if you use --help, you also should be using -help, and -h --h

I tend to go by the paradigm of single dash for single character options, and double dash for full words (and common things like —-help should have aliases like -h).



That's interesting. Did you come up with that yourself or is that a common standard?

I've always wondered why the style of command flags wasn't "more" standardized after 32 years of Linux being around (not that thats the first time flags were introduced, just an easy stop so I don't have to dig into that since it's not super relevant).

So, maybe it is somewhat/completely standardized and I'm just not aware of where that information is?

I think your style would still frustrate me. I'd first type "executable -help" thinking that was probably the - and -- option, and get a command not found error. I wouldn't think that think we're using - and -- differently.


That used to be a fairly common standard. You'll notice nearly all the old GNU / BSD tooling use this paradigm. It is even codified in GNU's coding principles. In fact, when you do that, you can even merge all the single character flags together. For example, I can type, `ls -lah` instead of `ls -l -a -h`. Pretty handy.

My pet peeve is commands not supporting -h for help and making me write --help. This is especially worse when the command already supports single character arguments.


Dont forget when it provides -help but not --help, and -h is is an invalid argument.



I've never even thought about this. I think this is kind of strange

> An option and its argument may or may not appear as separate tokens. (In other words, the whitespace separating them is optional.) Thus, -o foo and -ofoo are equivalent.

Thanks this is super helpful I never knew this was a GNU thing.


Note that there's an opposite convention that I think originated with the BSDs, where -ofoo is equivalent to -o -f -o -o


That only holds when 'o' and 'f' are both boolean "flags" taking no arguments. If 'f' is more like --file=x then it takes an argument.

More specifically, getopt(3) in POSIX lets programmers very this by giving a format string. "o:f" would make your example parse as "-o" "foo" while "of:" would make it parse as "-o" "-f" "oo" and an "of" format would make it parse as you describe, "-o" "-f" "-o" "-o".

( darnir mentioned parts of this above: https://news.ycombinator.com/item?id=38968612 using the term "single character flags" to indicate no argument. )

Also, while --long-option is GNU, gcc which is perhaps the aboriginal GNU command-line utility uses single dash as in, e.g. `gcc -pipe`, though it also accepts `gcc --help`. CL syntax remains quite varied in the wild.


Definitely not my idea, but is encouraged by built-in tools like python's argparse [0] or node's util.parseArgs [1] which definitely guide you toward's this "short"/"long" style.

[0]: https://docs.python.org/3/library/argparse.html

[1]: https://nodejs.org/api/util.html#utilparseargsconfig




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: