Are there any naming conventions for command line arguments?

12.3k views Asked by At

I'm reviewing a command line driven Java application with command line switches in lower camel case like this:

myapp aSwitch anotherSwitch aThirdSwitch

Am thinking all lower case and leading hyphens may be preferable:

myapp -aswitch -anotherswitch -athirdswitch

...or perhaps:

myapp -a-switch -another-switch -a-third-switch

... or maybe:

myapp --a-switch --another-switch --a-third-switch

...but struggling to come up with a compelling justification. Would like to follow current conventions and be cross-platform compatible, at least for Windows/Linux.

Seeking some advice on what is the most commonly used convention out of these - and any reasoning behind it.

2

There are 2 answers

0
Sharon Ben Asher On BEST ANSWER

Apache Commons CLI has a description of the commonly used convention. it is also a good parser for such use cases

2
Nagarz On

I work mostly on linux, but the usual is

app -<option1> <option1 value> -<option2> <option2 value> -<option2> <option3 value> 

If every option has a value or parameter to pass

myapp -o1 aSwitch -o2 anotherSwitch -o3 aThirdSwitch