Package it.cdq

Source Code of it.cdq.Main

package it.cdq;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class Main extends MainService {

  //@formatter:off
  @SuppressWarnings("static-access")
  private static Option exec = OptionBuilder.withArgName("file").hasArg() .withDescription("Help Message").create("logfile");
  private static Option help = new Option("help", "Help Message");
  private static Option startHub = new Option("startHub", "Help Message");
  private static Option stopHub = new Option("stopHub", "Help Message");
  private static Option startAll = new Option("startAll", "Help Message");
  //@formatter:on

  public static void main(String[] args) {

    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption(help);
    options.addOption(stopHub);
    options.addOption(startAll);
    options.addOption(stopHub);

    try {

      CommandLine line = parser.parse(options, args);

      if (line.hasOption("startAll"))
        startAll();

      if (line.hasOption("stopHub"))
        stopHub();

      if (line.hasOption("startHub"))
        startHub();

      if (line.hasOption("help") || line.getOptions().length == 0)
        help(options);

    } catch (ParseException exp) {
      logger.error("Comando non riconoscito. " + exp.getCause());
      help(options);
    }

  }

  public static void help(Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("codoqu", options, true);
  }
}
TOP

Related Classes of it.cdq.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.