Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any standard Command line conventions for dashes and arguments? [duplicate]

What are the command-line conventions regarding when to use 2 dashes, 1 dash, or simply no options at all and simply read inputs in order?

I realize there are many variants, but do any conventions stand out as the industry standard (say in Java, or C, or Python)?

like image 804
jayunit100 Avatar asked Nov 01 '11 12:11

jayunit100


2 Answers

Read up on the background section of Python's optparse module, it answers some of your questions and exemplifies with some common argument formatting standards seen in the wild. The optparse module author recommends a style that roughly corresponds to the POSIX conventions for command line arguments, with the addition of --double-dashed-long-arguments which comes from the GNU coding standard.

like image 62
Björn Lindqvist Avatar answered Oct 29 '22 21:10

Björn Lindqvist


It depends on your taste.

Unix convention is that commands have 2 forms: long and short (one character). To indicate long form we use 2 dashes --. For example --install. Short form is marked with one dash, e.g. -i.

But there is no rules without exceptions. For example command line option of java itself do not follow this convention: -cp and -classpath mean the same and both are marked with one dash only. -version does not have short alias etc.

Slashes are used in windows applications.

I as a java developer prefer to use platform independent conventions (dashes). Moreover various libraries (like cli from jakarta project) supports dashes, so it is easier to implement.

like image 38
AlexR Avatar answered Oct 29 '22 22:10

AlexR