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.
Answer from Gaslight Deceive Subvert on Stack Overflow
How can i create hyphen(-) parameters for a java program, such as java -enable-gui=true ExampleClass
Thanks
java - Are there any standard Command line conventions for dashes and arguments? - Stack Overflow
Java Command line arguments - Stack Overflow
parameters - What is the hyphen used for in shell script argument parsing? - Stack Overflow
command line - Single dashes `-` for single-character options, but double dashes `--` for words? - Unix & Linux Stack Exchange
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.
Use the apache commons cli if you plan on extending that past a single arg.
"The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool."
Commons CLI supports different types of options:
- POSIX like options (ie. tar -zxvf foo.tar.gz)
- GNU like long options (ie. du --human-readable --max-depth=1)
- Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
- Short options with value attached (ie. gcc -O2 foo.c)
- long options with single hyphen (ie. ant -projecthelp)
public class YourClass {
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("a")){
//...
}
}
}
In The Art of Unix Programming Eric Steven Raymond describes how this practice evolved:
In the original Unix tradition, command-line options are single letters preceded by a single hyphen... The original Unix style evolved on slow ASR-33 teletypes that made terseness a virtue; thus the single-letter options. Holding down the shift key required actual effort; thus the preference for lower case, and the use of “-” (rather than the perhaps more logical “+”) to enable options.
The GNU style uses option keywords (rather than keyword letters) preceded by two hyphens. It evolved years later when some of the rather elaborate GNU utilities began to run out of single-letter option keys (this constituted a patch for the symptom, not a cure for the underlying disease). It remains popular because GNU options are easier to read than the alphabet soup of older styles. 1
[1] http://www.catb.org/esr/writings/taoup/html/ch10s05.html
One reason for continuing to use the single letter options is because they can be strung together: ls -ltr is a lot easier to type than ls --sort=time --reverse --format=long. There are a number of times when both are good to use. As for searching for this topic, try "unix command line options convention".