Home > Uncategorized > Apache Commons CLI Example

Apache Commons CLI Example

HelpFormatter help = new HelpFormatter();

        Options options = new Options();
        options.addOption("h", "help", false, "print program usage");
        options.addOption("n", "name", true, "sets job name");
        CommandLineParser parser = new BasicParser();
        CommandLine cline;
        try {
            cline = parser.parse(options, args);
            args = cline.getArgs();
            if (args.length < 1) {
                help.printHelp(CMDLINE, options);
                return -1;
            }
        } catch (ParseException e) {
            System.out.println(e);
            e.printStackTrace();
            help.printHelp(CMDLINE, options);
            return -1;
        }
 
        String name = null;
        try {
            if (cline.hasOption('n'))
                name = cline.getOptionValue('n');
            else
                name = "wildnove.com - Tutorial MultiTableOutputFormat ";
Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: