List of usage examples for org.apache.commons.cli HelpFormatter HelpFormatter
HelpFormatter
From source file:jlite.cli.JobCancel.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/*from www . j ava2 s. c om*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } else { if (line.hasOption("xml")) { System.out.println("<output>"); } run(line.getArgs(), line); } } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:craterdog.security.DigitalNotaryMain.java
public static void main(String[] args) throws ParseException, IOException { HelpFormatter help = new HelpFormatter(); Options options = new Options(); options.addOption("help", false, "print this message"); options.addOption("pubfile", true, "public key input file"); options.addOption("prvfile", true, "private key input file"); try {/* w w w .ja v a 2 s. co m*/ CommandLine cli = new BasicParser().parse(options, args); String pubfile = cli.getOptionValue("pubfile"); String prvfile = cli.getOptionValue("prvfile"); NotaryKey notaryKey = notarization.generateNotaryKey(); if (pubfile != null || prvfile != null) { if (pubfile == null) throw new MissingArgumentException("Missing option: pubfile"); if (prvfile == null) throw new MissingArgumentException("Missing option: prvfile"); CertificateManager manager = new RsaCertificateManager(); PublicKey publicKey = manager.decodePublicKey(FileUtils.readFileToString(new File(pubfile))); char[] password = System.console().readPassword("input private key password: "); PrivateKey privateKey = manager.decodePrivateKey(FileUtils.readFileToString(new File(prvfile)), password); notaryKey.signingKey = privateKey; notaryKey.verificationKey = publicKey; // make sure it works DigitalSeal seal = notarization.notarizeDocument("test document", "test document", notaryKey); notarization.documentIsValid("test document", seal, publicKey); } char[] password = System.console().readPassword("verficationKey password: "); System.out.println(notarization.serializeNotaryKey(notaryKey, password)); } catch (MissingArgumentException | FileNotFoundException ex) { System.out.println(ex.getMessage()); help.printHelp(CMD_LINE_SYNTAX, options); System.exit(1); } }
From source file:cz.deco.Main.java
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); DecoContextImpl context = new DecoContextImpl(); Options options = getOptions();//from ww w.j av a 2 s . co m CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar deco.jar", options); return; } String source = cmd.getOptionValue("s"); String target = cmd.getOptionValue("t"); String plan = cmd.getOptionValue("p"); String temp = cmd.getOptionValue("d"); context.setOutputArchive(new File(target).getAbsoluteFile().toPath()); context.setApplicationArchive(new File(source).getAbsoluteFile().toPath()); Path temporaryDir; if (cmd.hasOption("d")) { temporaryDir = new File(temp).getAbsoluteFile().toPath(); } else { temporaryDir = getTempDirectory(); } context.setTemporaryDir(temporaryDir); context.setDeploymentPlan(new File(plan).getAbsoluteFile().toPath()); new Application().doWork(context); cleanUp(temporaryDir); }
From source file:it.anyplace.sync.webclient.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("C", "set-config", true, "set config file for s-client"); options.addOption("h", "help", false, "print help"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("s-client", options); return;/* www.ja v a 2s . co m*/ } File configFile = cmd.hasOption("C") ? new File(cmd.getOptionValue("C")) : new File(System.getProperty("user.home"), ".s-client.properties"); logger.info("using config file = {}", configFile); try (ConfigurationService configuration = ConfigurationService.newLoader().loadFrom(configFile)) { FileUtils.cleanDirectory(configuration.getTemp()); KeystoreHandler.newLoader().loadAndStore(configuration); logger.debug("{}", configuration.getStorageInfo().dumpAvailableSpace()); try (HttpService httpService = new HttpService(configuration)) { httpService.start(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse( URI.create("http://localhost:" + httpService.getPort() + "/web/webclient.html")); } httpService.join(); } } }
From source file:com.google.api.codegen.config.ConfigGeneratorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("descriptor_set") .desc("The descriptor set representing the compiled input protos.").hasArg() .argName("DESCRIPTOR-SET").required(true).build()); options.addOption(// ww w . j a va 2 s . com Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.") .hasArg().argName("OUTPUT-FILE").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("ConfigGeneratorTool", options); } generate(cl.getOptionValue("descriptor_set"), cl.getOptionValue("output")); }
From source file:com.google.cloud.trace.v1.TraceServiceSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {/*from www. j av a2s . c om*/ Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg() .argName("PROJECT-ID").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("TraceServiceSmokeTest", options); } executeNoCatch(cl.getOptionValue("project_id")); System.out.println("OK"); } catch (Exception e) { System.err.println("Failed with exception:"); e.printStackTrace(System.err); System.exit(1); } }
From source file:com.epitech.oliver_f.astextexls.MainClass.java
public static void main(String[] args) { initalizeOption();/*from w w w. java 2s . co m*/ CommandLineParser parser = new BasicParser(); CommandLine cl = null; try { cl = parser.parse(options, args); } catch (ParseException ex) { Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex); } if (cl != null && cl.hasOption("help")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("astexte script", options); } if (cl.hasOption("folder") && cl.hasOption("file")) { launchWriteAndRead(cl.getOptionValue("folder"), cl.getOptionValue("file")); System.out.println("OK"); } else { HelpFormatter hf = new HelpFormatter(); hf.printHelp("astexte script", options); } launch(args); }
From source file:io.github.dustalov.maxmax.Application.java
public static void main(String[] args) throws IOException { final CommandLineParser parser = new DefaultParser(); final Options options = new Options(); options.addOption(Option.builder("in").argName("in").desc("input graph in the ABC format").hasArg() .required().build());/*from w w w . j ava2s .c o m*/ options.addOption(Option.builder("out").argName("out").desc("name of cluster output file").hasArg() .required().build()); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (final ParseException ex) { System.err.println(ex.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar this.jar", options, true); System.exit(1); } final UndirectedGraph<String, DefaultWeightedEdge> graph = parse(cmd.getOptionValue("in"), ABCParser::parse); final MaxMax<String> maxmax = new MaxMax<>(graph); maxmax.run(); write(cmd.getOptionValue("out"), maxmax); }
From source file:ezbake.thrift.VisibilityBase64Converter.java
public static void main(String[] args) { try {// w ww .j a v a2 s. c om Options options = new Options(); options.addOption("d", "deserialize", false, "deserialize base64 visibility, if not present tool will serialize"); options.addOption("v", "visibility", true, "formalVisibility to serialize, or base64 encoded string to deserialize"); options.addOption("h", "help", false, "display usage info"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("thrift-visibility-converter", options); return; } String input = cmd.getOptionValue("v"); boolean deserialize = cmd.hasOption("d"); String output; if (deserialize) { if (input == null) { System.err.println("Cannot deserialize empty string"); System.exit(1); } output = ThriftUtils.deserializeFromBase64(Visibility.class, input).toString(); } else { Visibility visibility = new Visibility(); if (input == null) { input = "(empty visibility)"; } else { visibility.setFormalVisibility(input); } output = ThriftUtils.serializeToBase64(visibility); } String operation = deserialize ? "deserialize" : "serialize"; System.out.println("operation: " + operation); System.out.println("input: " + input); System.out.println("output: " + output); } catch (TException | ParseException e) { System.out.println("An error occurred: " + e.getMessage()); System.exit(1); } }
From source file:com.google.cloud.pubsub.v1.TopicAdminSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {//from w ww . j a v a2s. co m Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg() .argName("PROJECT-ID").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("TopicAdminSmokeTest", options); } executeNoCatch(cl.getOptionValue("project_id")); System.out.println("OK"); } catch (Exception e) { System.err.println("Failed with exception:"); e.printStackTrace(System.err); System.exit(1); } }