commons-cli OpenPatrician. . :
Options opts = new Options();
opts.addOption(HELP_OPTION, "help", false, "Display help");
opts.addOption(OptionBuilder.withLongOpt(VERSION_OPTION)
.withDescription("Version of this application")
.create());
opts.addOption(FULLSCREEN_MODE, "fullscreen", false, "fullscreen mode");
opts.addOption(OptionBuilder.withArgName(WINDOWED_MODE)
.withLongOpt("windowed")
.hasOptionalArgs(1)
.withArgName("widthxheight")
.withDescription("Windowed mode with optional definition of window size like: 1280x780")
.create());
opts.addOption(GAME_LOCALE, "lang", true, "Specify the locale to use");
opts.addOption(CLIENT_OPTION, "client", false, "Start application in client mode. Currently unused. Either client or server must be specified");
opts.addOption(SERVER_OPTION, "server", false, "Start application in server mode. Currently unused. Either client or server must be specified");
:
public void printHelp(Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "OpenPatrician", options );
}
, , :
public CommandLine parseCommandLine(Options options, String[] args) {
try {
CommandLineParser parser = new PosixParser();
return parser.parse( options, args );
}
catch( ParseException exp ) {
printHelp(options);
throw new IllegalArgumentException("Parsing of command line arguments failed", exp);
}
}
, PosixPaser , . , .