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)?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With