List of usage examples for org.apache.commons.cli Options Options
Options
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());/* w w w . j a v a 2 s .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:b2s.idea.mavenize.App.java
public static void main(String... args) throws ParseException { Options options = new Options(); options.addOption("i", "idea-dir", true, "Path to root directory of an intellij instance"); options.addOption("o", "output-dir", true, "Path to put the newly created jar"); if (args.length == 0) { error("", options); return;/* www .j a v a2 s.com*/ } PosixParser parser = new PosixParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("i")) { String ideaDirValue = commandLine.getOptionValue("i"); File ideaFolder = new File(ideaDirValue); if (!ideaFolder.exists()) { error("This path [" + ideaDirValue + "] can not be found", options); return; } File libFolder = new File(ideaFolder, "lib"); if (!libFolder.exists()) { error("The [lib] folder was not found in the IDEA folder", options); return; } if (commandLine.hasOption("output-dir")) { File output = new File(commandLine.getOptionValue("output-dir"), determineFilename(ideaFolder)); jarCombiner.combineAllJarsIn(libFolder, output); System.out.println("Combined Jar: " + output); } else { error("Please provide an output directory", options); } } else { error("Please provide the IDEA directory path", options); } }
From source file:io.github.sn0cr.rapidRunner.CommandlineInterface.java
public static void main(String[] args) { // create Options object final Options options = new Options(); // add t option // options.addOption("t", false, "display current time"); final CommandLineParser parser = new PosixParser(); try {//from ww w . j a v a 2 s . com final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("t")) { System.out.println("has option " + cmd.getOptionValue("t")); } else { System.out.println("hasn't option"); } } catch (final ParseException e) { e.printStackTrace(); } }
From source file:com.discursive.jccook.cmdline.CliBasicExample.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("v", "verbose", false, "Print out VERBOSE debugging information"); options.addOption("f", "file", true, "File to save program output to"); CommandLine commandLine = parser.parse(options, args); boolean verbose = false; String file = ""; if (commandLine.hasOption('h')) { System.out.println("Help Message"); System.exit(0);//from www . ja v a 2s.com } if (commandLine.hasOption('v')) { verbose = true; } if (commandLine.hasOption('f')) { file = commandLine.getOptionValue('f'); } System.exit(0); }
From source file:com.floragunn.searchguard.tools.Hasher.java
public static void main(final String[] args) { final Options options = new Options(); final HelpFormatter formatter = new HelpFormatter(); options.addOption(/* w ww.j a va 2 s .co m*/ Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build()); options.addOption(Option.builder("env").argName("name environment variable").hasArg() .desc("name environment variable to read password from").build()); final CommandLineParser parser = new DefaultParser(); try { final CommandLine line = parser.parse(options, args); if (line.hasOption("p")) { System.out.println(hash(line.getOptionValue("p").getBytes("UTF-8"))); } else if (line.hasOption("env")) { final String pwd = System.getenv(line.getOptionValue("env")); if (pwd == null || pwd.isEmpty()) { throw new Exception("No environment variable '" + line.getOptionValue("env") + "' set"); } System.out.println(hash(pwd.getBytes("UTF-8"))); } else { final Console console = System.console(); if (console == null) { throw new Exception("Cannot allocate a console"); } final char[] passwd = console.readPassword("[%s]", "Password:"); System.out.println(hash(new String(passwd).getBytes("UTF-8"))); } } catch (final Exception exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); formatter.printHelp("hasher.sh", options, true); System.exit(-1); } }
From source file:de.stz.bt.nanopubsub.StandaloneBroker.java
/** * Main Method for running the standalone Broker * /*from www.j a va 2 s . c o m*/ * @param args * @author jseitter */ public static void main(String[] args) { Options options = new Options(); options.addOption( OptionBuilder.hasArg(true).withArgName("port").withDescription("broker port number").create('p')); Parser parser = new PosixParser(); CommandLine cmdLine = null; try { cmdLine = parser.parse(options, args); } catch (ParseException e) { printHelp(options); } if (cmdLine == null) printHelp(options); new StandaloneBroker(cmdLine); }
From source file:io.stpettersen.bluejpackager.BlueJPackager.java
public static void main(String[] args) { // Create the command line parser. CommandLineParser parser = new DefaultParser(); // Create the command line options. Options options = new Options(); options.addOption("h", "help", false, "Display this help information and exit."); options.addOption("v", "version", false, "Display version information and exit."); options.addOption("p", "package", true, "Package string to use."); options.addOption("m", "mainClass", true, "Main class to use."); options.addOption("cp", "classPath", true, "Class path directory."); options.addOption("r", "root", true, "Root directory."); options.addOption("l", "verbose", false, "Be verbose."); try {// w ww .j a v a 2 s . com // Parse the command line arguments. CommandLine cli = parser.parse(options, args); if (cli.hasOption("h")) displayUsage(options, 0); } catch (Exception e) { // Bad command line option occurred. System.err.println("\nError: " + e.getMessage()); displayUsage(options, 1); } }
From source file:dyco4j.instrumentation.entry.CLI.java
public static void main(final String[] args) throws IOException { final Options _options = new Options(); _options.addOption(Option.builder().longOpt(IN_FOLDER_OPTION).required().hasArg() .desc("Folder containing the classes (as descendants) to be instrumented.").build()); _options.addOption(Option.builder().longOpt(OUT_FOLDER_OPTION).required().hasArg() .desc("Folder containing the classes (as descendants) with instrumentation.").build()); final String _msg = MessageFormat.format("Regex identifying the methods to be instrumented. Default: {0}.", METHOD_NAME_REGEX);//from w w w . j ava2 s.c o m _options.addOption(Option.builder().longOpt(METHOD_NAME_REGEX_OPTION).hasArg(true).desc(_msg).build()); _options.addOption(Option.builder().longOpt(ONLY_ANNOTATED_TESTS_OPTION).hasArg(false) .desc("Instrument only tests identified by annotations.").build()); try { processCommandLine(new DefaultParser().parse(_options, args)); } catch (final ParseException _ex) { new HelpFormatter().printHelp(CLI.class.getName(), _options); } }
From source file:main.Main.java
/** * The public main function./*from w w w. ja va 2 s. co m*/ * @param args */ public static void main(String[] args) { System.out.println("Starting"); Options options = new Options(); Option solutionOption = new Option("s", "solution", true, "This will be the " + "solution of the cross word game. (aka. This will be the first" + " vertical word on the canvas.)"); // solutionOption.setRequired(true); Option numOfBatchOption = new Option("n", "numOfBatch", true, ""); Option verboseOption = new Option("v", "verbose", false, "Print some debug information during running."); Option veryVerboseOption = new Option("vv", "very-verbose", false, "Print more debug information."); options.addOption(solutionOption); options.addOption(numOfBatchOption); options.addOption(verboseOption); options.addOption(veryVerboseOption); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); System.exit(1); return; } System.out.println(cmd.getArgList()); int debugLevel = 0; if (cmd.hasOption("verbose")) { debugLevel = 1; } if (cmd.hasOption("very-verbose")) { debugLevel = 2; } String solution = cmd.getOptionValue("solution"); if (null == solution) { startGui(); } else { int numOfBatch = Integer.valueOf(cmd.getOptionValue("numOfBatch", "200")); System.out.println(solution); Generator gen = new Generator(solution, debugLevel); // <---- EDIT THIS LINE FOR DIFFERENT SOLUTIONS. long startTime = System.currentTimeMillis(); gen.generate(numOfBatch); long estimatedTime = System.currentTimeMillis() - startTime; System.out.print("estimatedTime: " + estimatedTime + "ms"); } }
From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {//from www . ja v a 2s .c o m CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }