当前位置: 首页>>代码示例>>Java>>正文


Java HelpFormatter类代码示例

本文整理汇总了Java中org.apache.commons.cli.HelpFormatter的典型用法代码示例。如果您正苦于以下问题:Java HelpFormatter类的具体用法?Java HelpFormatter怎么用?Java HelpFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HelpFormatter类属于org.apache.commons.cli包,在下文中一共展示了HelpFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    try {
        Options options = getOptions();
        CommandLine line = parser.parse(options, args );
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            System.out.println(Constants.PROJECT_NAME + ", " + Constants.PROJECT_URL);
            formatter.printHelp(Constants.PROJECT_NAME, options, true);
        } else if (line.hasOption("version")) {
            System.out.println("version: " + Constants.VERSION);
        } else {
            logger.info("Starting pm-home-station ({} v.{})...", Constants.PROJECT_URL, Constants.VERSION);
            setLookAndFeel();
            PlanTowerSensor planTowerSensor = new PlanTowerSensor();
            Station station = new Station(planTowerSensor);
            SwingUtilities.invokeLater(() -> { station.showUI(); });
        }
    } catch (ParseException e) {
        logger.error("Ooops", e);
        return;
    }
}
 
开发者ID:rjaros87,项目名称:pm-home-station,代码行数:24,代码来源:Start.java

示例2: usage

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
private static void usage() {
	// automatically generate the help statement
	HelpFormatter formatter = new HelpFormatter();
	String helpMsg = USAGE;
	
	if (OpMode.PROFILE.equals(CliOptions.opmode))
		helpMsg = USAGE_PROFILE;
	else if (OpMode.MATCH.equals(CliOptions.opmode))
		helpMsg = USAGE_MATCH;
	else if (OpMode.DB.equals(CliOptions.opmode))
		helpMsg = USAGE_DB;
	else if (OpMode.LIB_API_ANALYSIS.equals(CliOptions.opmode))
		helpMsg = USAGE_LIB_API_ANALYSIS;

	formatter.printHelp(helpMsg, options);
	System.exit(1);
}
 
开发者ID:reddr,项目名称:LibScout,代码行数:18,代码来源:TplCLI.java

示例3: main

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  CommandLineParser parser = new DefaultParser();
  CommandLine line = parser.parse(CLI_OPTIONS, args);
  if (!line.hasOption("conf")) {
    System.err.println("No configuration file is specified");
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("athenax-server", CLI_OPTIONS);
    System.exit(1);
  }

  try {
    String confFile = line.getOptionValue("conf");
    AthenaXConfiguration conf = AthenaXConfiguration.load(Paths.get(confFile).toFile());
    new AthenaXServer().start(conf);
  } catch (IOException | ClassNotFoundException e) {
    System.err.println("Failed to parse configuration.");
    throw e;
  }
}
 
开发者ID:uber,项目名称:AthenaX,代码行数:20,代码来源:AthenaXServer.java

示例4: parseCmdLine

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
    CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }

    return commandLine;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:18,代码来源:ServerUtil.java

示例5: printUsage

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
/**
 * Prints usage
 * 
 * @param options
 *            the CLI Options
 */
private static void printUsage(Options options) {
	// automatically generate the help statement
	HelpFormatter formatter = new HelpFormatter();
	formatter.setWidth(400);

	String fromAceqlServerScript = System.getProperty("from.aceql-server.script");

	String help = null;

	if (fromAceqlServerScript != null && fromAceqlServerScript.equals("true")) {
		help = "aceql-server -start -host <hostname> -port <port> -properties <file>" + CR_LF + "or " + CR_LF
				+ "-stop -port <port> ";
	} else {
		help = "java org.kawanfw.sql.WebServer -start -host <hostname> -port <port> -properties <file>" + CR_LF
				+ "or " + CR_LF + "-stop -port <port> ";
	}

	formatter.printHelp(help, options);
	System.out.println();
}
 
开发者ID:kawansoft,项目名称:aceql-http,代码行数:27,代码来源:WebServer.java

示例6: printHelp

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
private static void printHelp() throws Exception {

        String cmd = "<CMD>";
        String CRLF = "\r\n";
        StringWriter subCommandsHelp = new StringWriter();

            commands.stream().map(it -> it.getAnnotation(CommandDescriptor.class).name())
            .sorted().forEach(subcmd ->
            subCommandsHelp.append(StringUtils.repeat(' ', 4))
                           .append(subcmd)
                           .append(CRLF)
        );

        String cmdLineSyntax = format("%s [COMMON_OPTIONS...] <subcommand> [SUBCOMMAND_OPTIONS] <parameters...>", cmd);
        String header = "Manages communication with the SAP CM System.\r\nCOMMON OPTIONS:";
        String footer = format("Subcommands:%s%s%sType '%s <subcommand> --help' for more details.%s",
            CRLF, subCommandsHelp.toString(), CRLF, cmd, CRLF);

        new HelpFormatter().printHelp(
            cmdLineSyntax, header,
            Helpers.getStandardOptions(),
            footer);
    }
 
开发者ID:SAP,项目名称:devops-cm-client,代码行数:24,代码来源:Commands.java

示例7: prepareCLI

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
/**
 * @param args cmd params
 */
public QConfig prepareCLI(String[] args) {
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        throw new RuntimeException("Parsing failed.  Reason: ", exp);
    }

    new HelpFormatter().printHelp("command line parameters for QMS QSystem...", options);
    // automatically generate the help statement
    if (line.hasOption("help") || line.hasOption("h") || line.hasOption("?")) {

        System.exit(0);
    }

    QLog.l().logger().info("Properties are ready.");
    return this;
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:23,代码来源:QConfig.java

示例8: main

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
public static void main(String[] args) {
    Options options = getOptions();
    CommandLine cmd = null;
    try {
        cmd = parseCommandLineArgs(options, args);
    } catch (ParseException e) {
        System.out.format("%s.%n", e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ConsoleReader", options);
        System.exit(1);
    }
    
    final String scope = cmd.getOptionValue("scope") == null ? Constants.DEFAULT_SCOPE : cmd.getOptionValue("scope");
    final String streamName = cmd.getOptionValue("name") == null ? Constants.DEFAULT_STREAM_NAME : cmd.getOptionValue("name");
    final String uriString = cmd.getOptionValue("uri") == null ? Constants.DEFAULT_CONTROLLER_URI : cmd.getOptionValue("uri");
    final URI controllerURI = URI.create(uriString);
    
    ConsoleReader reader = new ConsoleReader(scope, streamName, controllerURI);
    reader.run();
}
 
开发者ID:pravega,项目名称:pravega-samples,代码行数:21,代码来源:ConsoleReader.java

示例9: main

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("q", true, "Queue");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {

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

      if (cmd.hasOption("u")) {

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Sender", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String address = cmd.getOptionValue("q", QUEUE);

        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
        props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort));
        props.put("queue.myDestinationLookup", address);

        LOG.info("Starting server : connecting to [{}:{}]", messagingHost, messagingPort);

        Server sender = new Server();
        sender.run(props);
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
 
开发者ID:ppatierno,项目名称:amqp-kafka-demo,代码行数:41,代码来源:Server.java

示例10: main

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  CommandLine cmd = new GnuParser().parse(opts, args);
  if (cmd.hasOption("help")) {
    new HelpFormatter().printHelp("Usage: hbgen [OPTIONS]", opts);
    return;
  }
  // defaults
  Class<?> specClass = HamletSpec.class;
  Class<?> implClass = HamletImpl.class;
  String outputClass = "HamletTmp";
  String outputPackage = implClass.getPackage().getName();
  if (cmd.hasOption("spec-class")) {
    specClass = Class.forName(cmd.getOptionValue("spec-class"));
  }
  if (cmd.hasOption("impl-class")) {
    implClass = Class.forName(cmd.getOptionValue("impl-class"));
  }
  if (cmd.hasOption("output-class")) {
    outputClass = cmd.getOptionValue("output-class");
  }
  if (cmd.hasOption("output-package")) {
    outputPackage = cmd.getOptionValue("output-package");
  }
  new HamletGen().generate(specClass, implClass, outputClass, outputPackage);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:HamletGen.java

示例11: printUsage

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
/**
 * Prints the usage message and exits.
 *
 * @param options The command line {@code Options}.
 * @param status The status to exit with.
 */
private static void printUsage(Options options, int status) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("java -Xmx 256M -jar freecol.jar [OPTIONS]",
                        options);
    System.exit(status);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:13,代码来源:FreeCol.java

示例12: printHelpExtra

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
@Override
	public void printHelpExtra(PrintStream out, List args)
	{
		HelpFormatter formatter = new HelpFormatter();
		PrintWriter writer = new PrintWriter(out);
		writer.println("> -----");
		writer.println(getCommandDescriptions());
//		formatter.printHelp(writer, 80, getCommandDescriptions(), ">>>", getOptions(), 4, 4, ">>>", true);
		formatter.printOptions(writer, 80, getOptions(), 4, 4);
		writer.println("> -----");
		writer.flush();
	}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:13,代码来源:OptionsConsoleCommand.java

示例13: parseCommandLine

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
protected void parseCommandLine(String[] args)
    throws DaemonInitException, ConfigurationException, BiremeException {
  Option help = new Option("help", "print this message");
  Option configFile =
      Option.builder("config_file").hasArg().argName("file").desc("config file location").build();

  Options opts = new Options();
  opts.addOption(help);
  opts.addOption(configFile);
  CommandLine cmd = null;
  CommandLineParser parser = new DefaultParser();

  try {
    cmd = parser.parse(opts, args);

    if (cmd.hasOption("help")) {
      throw new ParseException("print help message");
    }
  } catch (ParseException e) {
    HelpFormatter formatter = new HelpFormatter();
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    formatter.printHelp(writer, formatter.getWidth(), "Bireme", null, opts,
        formatter.getLeftPadding(), formatter.getDescPadding(), null, true);
    writer.flush();
    String result = out.toString();
    throw new DaemonInitException(result);
  }

  String config = cmd.getOptionValue("config_file", DEFAULT_CONFIG_FILE);

  cxt = new Context(new Config(config));
}
 
开发者ID:HashDataInc,项目名称:bireme,代码行数:34,代码来源:Bireme.java

示例14: usage

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
private static void usage(CommandLine commandLine) {

        // load basicOptions
        _Options();
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);

        // print out license info prior to formatter.
        System.out.println(
                "Apktool v" + Androlib.getVersion() + " - a tool for reengineering Android apk files\n" +
                        "with smali v" + ApktoolProperties.get("smaliVersion") +
                        " and baksmali v" + ApktoolProperties.get("baksmaliVersion") + "\n" +
                        "Copyright 2014 Ryszard Wiśniewski <[email protected]>\n" +
                        "Updated by Connor Tumbleson <[email protected]>\n");
        if (isAdvanceMode()) {
            System.out.println("Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)\n");
        }else {
            System.out.println("");
        }

        // 4 usage outputs (general, frameworks, decode, build)
        formatter.printHelp("apktool " + verbosityHelp(), normalOptions);
        formatter.printHelp("apktool " + verbosityHelp() + "if|install-framework [options] <framework.apk>", frameOptions);
        formatter.printHelp("apktool " + verbosityHelp() + "d[ecode] [options] <file_apk>", DecodeOptions);
        formatter.printHelp("apktool " + verbosityHelp() + "b[uild] [options] <app_path>", BuildOptions);
        if (isAdvanceMode()) {
            formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>",
                    "Make all framework resources public.", emptyOptions, null);
        } else {
            System.out.println("");
        }

        // print out more information
        System.out.println(
                "For additional info, see: http://ibotpeaches.github.io/Apktool/ \n"
                        + "For smali/baksmali info, see: https://github.com/JesusFreke/smali");
    }
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:38,代码来源:Main.java

示例15: main

import org.apache.commons.cli.HelpFormatter; //导入依赖的package包/类
/**
 * 	Flink-charts batch job. Giving the parameters:
 *
 * 	chart 3
 *
 * 	Should output the top 3 most tagged tracks irrespective of user location. The output should
 * 	be in a columnar format and contain the following fields:
 * 	CHART POSITION , TRACK TITLE , ARTIST NAME
 *
 * 	Thus, the output may be as follows:
 * 		1 Shape Of You Ed Sheeran
 * 		2 24k Magic Bruno Mars
 * 		3 This Girl Kungs
 *
 *  Similarly, giving the parameters:
 *
 *  state_chart 3
 *
 *  Should output the top 3 tracks in each and every US state. The output format for the state
 *  chart should be similar to the above, but you are free to define it.
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

	ArgsParser argsParser= null;

	try {
		log.debug("Parsing input parameters ");
		argsParser= ArgsParser.builder(args);

	} catch (ParseException ex)	{
		log.error("Unable to parse arguments");
		HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp(CLI_CMD, ArgsParser.getDefaultOptions());
		System.exit(1);
	}

	log.debug("Initializing job: " + argsParser.toString());
	PipelineChartsConf pipelineConf= new PipelineChartsConf(argsParser);

	if (argsParser.getChartType().equals(ArgsParser.chartTypeOptions.chart.toString())) {
		log.debug("Starting Simple Charts job. Getting top track chart!");
		SimpleChartsPipeline.run(pipelineConf);

	} else if (argsParser.getChartType().equals(ArgsParser.chartTypeOptions.state_chart.toString())) {
		log.debug("Starting State Charts job. Getting top track charts by State (country: " +
				argsParser.getConfig().getString("ingestion.stateChart.country")+ ").");
		StateChartsPipeline.run(pipelineConf);

	} else	{
		log.error("Unable to parse arguments");
		System.exit(1);
	}


}
 
开发者ID:aaitor,项目名称:flink-charts,代码行数:58,代码来源:BatchMain.java


注:本文中的org.apache.commons.cli.HelpFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。