List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
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;/* w ww . j a va2 s . c om*/ } 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:com.github.jjYBdx4IL.utils.lang.ConstantClassCreator.java
public static void main(String[] args) { try {//from w ww . ja v a 2 s.c o m CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption(OPTNAME_H, OPTNAME_HELP, false, "show help (this page)"); options.addOption(null, OPTNAME_SYSPROP, true, "system property name(s)"); options.addOption(null, OPTNAME_OUTPUT_CLASSNAME, true, "output classname"); options.addOption(null, OPTNAME_OUTPUT_DIRECTORY, true, "output directory"); CommandLine line = parser.parse(options, args); if (line.hasOption(OPTNAME_H)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ConstantClassCreator.class.getName(), options); } else if (line.hasOption(OPTNAME_SYSPROP)) { new ConstantClassCreator().run(line); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.uber.tchannel.ping.PingClient.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "host", true, "Server Host to connect to"); options.addOption("p", "port", true, "Server Port to connect to"); options.addOption("n", "requests", true, "Number of requests to make"); options.addOption("?", "help", false, "Usage"); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("?")) { formatter.printHelp("PingClient", options, true); return;//from w w w . jav a 2s.co m } String host = cmd.getOptionValue("h", "localhost"); int port = Integer.parseInt(cmd.getOptionValue("p", "8888")); int requests = Integer.parseInt(cmd.getOptionValue("n", "10000")); System.out.println(String.format("Connecting from client to server on port: %d", port)); new PingClient(host, port, requests).run(); System.out.println("Stopping Client..."); }
From source file:com.retroduction.carma.application.Carma.java
/** * command line test runner, reads configuration from mutationconfig.xml * //from w w w . ja v a 2s . c o m * @throws ParseException * @throws IOException */ public static void main(String[] args) throws ParseException { CommandLine line = new CLIValidator().readCLI(args); File customPropertiesFile; if (line.hasOption(CLIValidator.USER_CONFIG_OPTION_SHORT)) { customPropertiesFile = new File(line.getOptionValue(CLIValidator.USER_CONFIG_OPTION_SHORT)); } else { customPropertiesFile = new File(DEFAULT_USER_CONFIG); } CarmaDriverSetup setup = new CarmaDriverSetup(); Properties customProps = new Properties(); try { customProps.load(new FileInputStream(customPropertiesFile)); } catch (IOException e) { throw new CarmaException("Failed to load configuration", e); } setup.addCustomConfiguration(customProps); Core driver = setup.getDriver(); driver.execute(); }
From source file:net.librec.tool.driver.RecDriver.java
public static void main(String[] args) throws Exception { LibrecTool tool = new RecDriver(); Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("exec", false, "run job"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("build")) { ;/*from w w w . j a va2 s .c o m*/ } else if (cmd.hasOption("load")) { ; } else if (cmd.hasOption("save")) { ; } else if (cmd.hasOption("exec")) { tool.run(args); } }
From source file:net.oneandone.shared.artifactory.App.java
public static void main(String[] args) throws ParseException, IOException, NotFoundException { initLogging();//from w w w . j a va 2s . c om LOG.info("CLI: {}", Arrays.toString(args)); final Options options = new Options() .addOption("l", "uri", true, "Base-URI in the form of " + DEFAULT_ARTIFACTORY_URI) .addOption("u", "user", true, "Username").addOption("p", "password", true, "Password") .addOption("d", "debug", false, "Turn on debugging"); final CommandLine commandline = new BasicParser().parse(options, args); if (commandline.hasOption("d")) { LOG.info("Setting debug"); java.util.logging.Logger.getLogger("net.oneandone.shared.artifactory").setLevel(Level.ALL); } final List<String> argList = commandline.getArgList(); LOG.info("ARGS: {}", argList); Injector injector = Guice.createInjector(new ArtifactoryModule()); App instance = injector.getInstance(App.class); instance.preemptiveRequestInterceptor.addCredentialsForHost("web.de", "foo", "bar"); List<ArtifactoryStorage> search = instance.searchByGav.search("repo1-cache", Gav.valueOf(argList.get(0))); LOG.info("Got {} search results", search.size()); }
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 w w w . ja v a 2s. co 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); } }
From source file:name.ikysil.beanpathdsl.codegen.CLI.java
/** * @param args the command line arguments *//* w w w . j a v a 2 s .co m*/ public static void main(String[] args) { final Options options = buildOptions(); try { CommandLineParser parser = new DefaultParser(); CommandLine cmdLine = parser.parse(options, args); if (cmdLine.hasOption("h")) { usage(options); System.exit(1); } Configuration configuration = new Configuration(); if (cmdLine.hasOption("s")) { configuration.setOutputDirectory(cmdLine.getOptionValue("s")); } if (cmdLine.hasOption("c")) { configuration.setOutputCharset(Charset.forName(cmdLine.getOptionValue("c"))); } if (cmdLine.hasOption("cnp")) { configuration.setClassNamePrefix(cmdLine.getOptionValue("cnp")); } if (cmdLine.hasOption("cns")) { configuration.setClassNameSuffix(cmdLine.getOptionValue("cns")); } if (cmdLine.hasOption("pnp")) { configuration.setPackageNamePrefix(cmdLine.getOptionValue("pnp")); } if (cmdLine.hasOption("pns")) { configuration.setPackageNameSuffix(cmdLine.getOptionValue("pns")); } new CodeGen(configuration).process(); } catch (ParseException ex) { System.err.println(String.format("Can not parse arguments: %s", ex.getMessage())); usage(options); } }
From source file:com.mosso.client.cloudfiles.sample.FilesMakeContainer.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/* w ww . j a va2s.c om*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); String containerName = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); createContaier(containerName); } //end if (line.hasOption("container")) else if (args.length > 0) { //If we got this far there are command line arguments but none of what we expected treat the first one as the Container name containerName = args[0]; createContaier(containerName); } else { System.err.println("You must provide the -container with a valid value for this to work !"); System.exit(-1); } } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (IOException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:de.akadvh.view.Main.java
/** * @param args//w w w.j av a 2 s. c o m */ public static void main(String[] args) { Options options = new Options(); options.addOption("u", "user", true, "Benutzername"); options.addOption("p", "pass", true, "Passwort"); options.addOption("c", "console", false, "Consolenmodus"); options.addOption("v", "verbose", false, "Mehr Ausgabe"); options.addOption("m", "modul", true, "Modul"); options.addOption("n", "noten", false, "Notenuebersicht erstellen"); options.addOption("t", "termin", false, "Terminuebersicht (angemeldete Module) downloaden"); options.addOption("version", false, "Version"); options.addOption("h", "help", false, "Hilfe"); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar akadvh.jar", options); System.exit(0); } if (cmd.hasOption("version")) { System.out.println("Akadvh Version: " + Akadvh.getVersion()); System.exit(0); } if (cmd.hasOption("console")) { ConsoleView cv = new ConsoleView(cmd.getOptionValue("user"), cmd.getOptionValue("pass"), cmd.getOptionValue("modul"), cmd.hasOption("noten"), cmd.hasOption("termin"), cmd.hasOption("verbose")); } else { SwingView sv = new SwingView(cmd.getOptionValue("user"), cmd.getOptionValue("pass")); } } catch (UnrecognizedOptionException e1) { System.out.println(e1.getMessage()); System.out.println("--help fuer Hilfe"); } catch (ParseException e) { e.printStackTrace(); } }