documenting command line arguments

I'm very new to javadoc, and I'm trying to put together a set of guidelines for our developers to follow. One thing I came accross was command line arguments. If a main function is expecting command line arguments, how would this be documented, should @param be used? I didn't see anything about this in the guidelines sun has posted. Any help is greatly appreciated.

[377 byte] By [bchristesena] at [2007-9-27 8:31:57]
# 1

This is my own personal opinion, so don't treat it as a "fact", but I don't think Javadoc is best suited for specifying command line arguments. You *could* do the following:

/**

* Description of main() here...

*

* @param args First parameter = xxx, Second parameter = yyy;

*/

public static void main(String[] args)

{

...

}

In this way you can specify all command-line parameters that are required in order to make the appliction run.

BUT...

Javadoc is meant more to be a programmatic guide to how to allow Java classes to interoperate. Java classes (mostly) will not care at all what the command-line parameters to the main invocation are. That is information that is only really needed to be known by the application executor at runtime.

Therefore, for all my apps, I do the following to comment what types of parameters should be passed to the invocation of the application:

/*

* My App comments...

*

* @param args Run application without any parameters to see list of all necessary command-line parameters.

*/

public static void main(String[] args)

{

if (args.length < 1)

{

System.out.println("This application allows the following parameters:");

System.out.println("Param#1 = xxx, <description>");

System.out.println("Param#2 = yyy, <description>");

System.exit(0);

}

}

In this way, you do not clutter up the Javadoc APIs (used for classwise interaction) with command-line parameters, but the command-line parameters are still specified by "documentation" (running the application without any parameters).

If parameters are optional, instead of mandatory, you could do something similar...

/*

* Documentation...

*

* @param args Run -h as first flag for list of all optional parameters.

*/

public static void main(String[] args)

{

if ((args.length > 0) && (args[0].equals("-h"))

{

// Print out all possible parameters.

}

}

Anyway, this system has held me in good stead for the last couple of years.

jre95001a at 2007-7-8 16:39:07 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Actually, I agree with the first poster that there should be a better way to document params (or returns) where it is a fixed size array with certain values for each element. This could be used in many places beside command line. Maybe you could make a Doclet or Taglet for this.
smhaus_neta at 2007-7-8 16:39:07 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
thanks for your input guys, it looks like we're just going to leave the documentation of the command line arguments to the usage statement instead of javadoc. I do agree that it would be nice if there was an easy way to do it in javadoc, though.
bchristesena at 2007-7-8 16:39:07 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

Javadoc comments and usage statements normally serve

entirely different audiences -- Javadoc comments

are for developers and usage statements are for users.

If you want developers to see these comments, you

could certainly do something like the following.

The second argument to @param can be any free-form

text.

/*

* My App comments...

*

* @param args

*This application allows the following parameters:

*<ul>

*<li> xxx - <description of xxx>

*<li> yyy - <description of yyy>

*</ul>

*Run application without any parameters to see list of all necessary command-line parameters.

*/

Of course, this isn't as nice as having tags dedicated

to those parameters. You could write to do

something more sophisticated which would move the

<ul> and <li> tags into the taglet. If you'd like

such a taglet, I could write one for you.

-Doug Kramer

Javadoc team

dkramera at 2007-7-8 16:39:07 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

I think you could also make a custom in-line formatting for the param test.

Until then, I do usually just put it into the body unformatted. Since it is for programmers, I think that indicies usually suffice.

i.e.

/**

* The method.

@param argArray [0] value 1 description, [1] value 2 description, ...

*/

or if you used an ordered list, starting at 0.

/**

* The method.

@param argArray

* <OL START=0 TYPE="1">

*<LI>value 1 description</LI>

*<LI>value 2 description</LI>

...

* </OL>

*/

smhaus_neta at 2007-7-8 16:39:07 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6
by you, I meant whoever wanted to use it.dkramer - thank you for the offer, but since people would probably want it to do different custom things, it might be easier to use HTML formatting or write our own javadoc add-on.
smhaus_neta at 2007-7-8 16:39:07 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...