List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:havocx42.Program.java
public static void main(String[] args) throws ParseException { try {//from w ww.j av a 2s . co m initRootLogger(); } catch (SecurityException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return; } try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) { LOGGER.log(Level.WARNING, "Unable to set Look and Feel", e1); } Options options = new Options(); options.addOption("nogui", false, "run as a command line tool, must also supply -target and -source arguments"); options.addOption("source", true, "source directory where the PR weapons folder has been extracted"); options.addOption("target", true, "target file to write to"); options.addOption("version", false, "print the version information and exit"); options.addOption("help", false, "print this message"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("version")) { System.out.println("PRStats " + VERSION); System.out.println("Written by havocx42"); return; } if ((cmd.hasOption("nogui") && (!cmd.hasOption("source") || !cmd.hasOption("target"))) || cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PRStats", options); return; } final String target; final String source; source = cmd.getOptionValue("source"); target = cmd.getOptionValue("target"); LOGGER.info("Source Argument: " + source); LOGGER.info("Target Argument: " + target); if (!cmd.hasOption("nogui")) { EventQueue.invokeLater(new Runnable() { @SuppressWarnings("unused") public void run() { try { Gui window = new Gui(source, target); } catch (Exception e) { e.printStackTrace(); } } }); return; } File targetFile = new File(target); File sourceFile = new File(source); Controller controller = new Controller(); controller.run(sourceFile, targetFile); }
From source file:com.github.xwgou.namesurfer.fxui.JFXNameSurfer.java
public static void main(String[] args) { JSurferOptions options = new JSurferOptions(); HelpFormatter formatter = new HelpFormatter(); String cmd_line_syntax = "namesurfer [options]"; String help_header = "NameSurfer renders beautiful algebraic surfaces derived from your name."; String help_footer = ""; try {// w w w . ja v a 2 s . c o m CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(JSurferOptions.HELP)) { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); return; } if (cmd.hasOption(JSurferOptions.VERSION)) { System.out.println(JFXNameSurfer.class.getPackage().getImplementationVersion()); return; } fullscreen = cmd.hasOption(JSurferOptions.FULLSCREEN); disable_buttons = cmd.hasOption(JSurferOptions.DISABLE_BUTTONS); InputStream rules = PinyinTranslator.RULES_PATH.openStream(); if (cmd.hasOption(JSurferOptions.RULES)) { rules = new FileInputStream(cmd.getOptionValue(JSurferOptions.RULES)); } InputStream keywords = PinyinTranslator.KEYWORDS_PATH.openStream(); if (cmd.hasOption(JSurferOptions.KEYWORDS)) { keywords = new FileInputStream(cmd.getOptionValue(JSurferOptions.KEYWORDS)); } translator = new PinyinTranslator(rules, keywords); launch(args); } catch (Throwable t) { logger.error("Exception during application startup", t); formatter.printHelp("help", options); System.exit(-1); } }
From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java
public static void main(String[] args) { Options options = new Options(); options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS"); options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project"); options.addOption(OVERWRITE_OPT, "overwrite", false, "overwrite existing messages by changed messages from XLS file"); options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory"); options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations"); options.addOption(LOG_FILE_OPT, "logFile", true, "log file"); options.addOption(LANGUAGES_OPT, "languages", true, "list of locales separated by comma, for example: 'de,fr'"); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try {//from w w w .j av a 2 s . c o m cmd = parser.parse(options, args); if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT) || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) { System.out.println("Please provide either 'read' or 'write' option"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT)); if (cmd.hasOption(READ_OPT)) { LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); localizationsBatch.setScanLocalizationIds(languages); LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT)); } else if (cmd.hasOption(WRITE_OPT)) { LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); sourceLocalization.setScanLocalizationIds(languages); LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT), cmd.getOptionValue(PROJECT_DIR_OPT)); fileLocalization.setScanLocalizationIds(languages); LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization, fileLocalization); String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT)) ? cmd.getOptionValue(LOG_FILE_OPT) : "log.xls"; fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT)); } } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } }
From source file:com.redhat.akashche.wixgen.cli.Launcher.java
public static void main(String[] args) throws Exception { try {/* w w w .ja v a2s . c om*/ CommandLine cline = new GnuParser().parse(OPTIONS, args); if (cline.hasOption(VERSION_OPTION)) { out.println(VERSION); } else if (cline.hasOption(HELP_OPTION)) { throw new ParseException("Printing help page:"); } else if (1 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION) && cline.hasOption(OUTPUT_OPTION) && !cline.hasOption(XSL_OPTION)) { WixConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION)); Wix wix = new DirectoryGenerator().createFromDir(new File(cline.getArgs()[0]), conf); Marshaller marshaller = createMarshaller(); writeXml(marshaller, wix, cline.getOptionValue(OUTPUT_OPTION), false); if (cline.hasOption(DIRECTORY_OPTION)) { Directory dir = findWixDirectory(wix); writeXml(marshaller, dir, cline.getOptionValue(DIRECTORY_OPTION), true); } if (cline.hasOption(FEATURE_OPTION)) { Feature feature = findWixFeature(wix); writeXml(marshaller, feature, cline.getOptionValue(FEATURE_OPTION), true); } } else if (1 == cline.getArgs().length && cline.hasOption(XSL_OPTION) && cline.hasOption(OUTPUT_OPTION)) { transformWithXsl(cline.getArgs()[0], cline.getOptionValue(XSL_OPTION), cline.getOptionValue(OUTPUT_OPTION)); } else { throw new ParseException("Incorrect arguments received!"); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); out.println(e.getMessage()); out.println(VERSION); formatter.printHelp("java -jar wixgen.jar input_dir -c config.json -o output.wxs", OPTIONS); } }
From source file:net.anthonypoon.ngram.removespecial.Main.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); options.addOption("c", "compressed", false, "is lzo zipped"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); Job job = Job.getInstance(conf);// w w w .j a va 2 s . c o m if (cmd.hasOption("compressed")) { job.setInputFormatClass(SequenceFileAsTextInputFormat.class); } job.setJarByClass(Main.class); //job.setInputFormatClass(SequenceFileAsTextInputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); switch (cmd.getOptionValue("action")) { case "list": job.setMapperClass(ListMapper.class); //job.setNumReduceTasks(0); job.setReducerClass(ListReducer.class); break; case "remove": job.setMapperClass(RemoveMapper.class); job.setReducerClass(RemoveReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:com.bachelor.boulmier.workmaster.WorkMaster.java
public static void main(String[] args) throws IOException, InterruptedException { defineOptions();/*from ww w .j a va2 s . c o m*/ CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (cmd.hasOption(MasterConfig.CMD.CLILONGOPT)) { cliEnabled = true; } if (cmd.hasOption(MasterConfig.CMD.DEBUGLONGOPT)) { debug = true; } if (cmd.hasOption(MasterConfig.CMD.MAXVMLONGOPT)) { maxVM = Integer.valueOf(cmd.getOptionValue(MasterConfig.CMD.MAXVMLONGOPT)); } if (cmd.hasOption(MasterConfig.CMD.VERBOSELONGOPT)) { verbose = true; } if (cmd.hasOption(MasterConfig.CMD.REMOTEWSLONGOPT)) { webServer = cmd.getOptionValue(MasterConfig.CMD.REMOTEWSLONGOPT); if (!MasterConfig.DEFAULT.IP_PORT_PATTERN.matcher(webServer).matches()) { throw new ParseException("Given IP:PORT does not match pattern"); } } if (cmd.hasOption(MasterConfig.CMD.HELPLONGOPT)) { printHelp(); } logger = LoggerFactory.getLogger(); QueuingService.get() .send(RequestBuilder.builder().withExecutableName(ExecutableName.CAT) .with(RequestProperty.CLIENT_EMAIL, "anthony.boulmier.cfpt@gmail.com") .with(RequestProperty.JOB_IDENTIFIER, UUID.randomUUID().toString()) .with(RequestProperty.ARGS, "JobExecutor.log").create()); Thread.sleep(3000); } catch (ParseException pe) { logger.error(pe.getMessage()); printHelp(); } }
From source file:com.mosso.client.cloudfiles.sample.FilesRemove.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/*from ww w . j ava 2 s . c o m*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { printHelp(options); System.exit(0); } if (line.hasOption("container")) { String containerName = null; containerName = line.getOptionValue("container"); removeContainer(containerName, line.hasOption('r')); } //if (line.hasOption("container")) if (line.hasOption("object")) { String ObjectNameWithPath = null; ObjectNameWithPath = line.getOptionValue("object"); removeObject(ObjectNameWithPath); } //if (line.hasOption("container")) } //end try catch (ParseException err) { logger.fatal("Parsing exception on the command line: " + 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) { logger.fatal("IOException : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesRemove.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/*ww w. ja v a 2s . c o m*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { printHelp(options); System.exit(0); } if (line.hasOption("container")) { String containerName = null; containerName = line.getOptionValue("container"); removeContainer(containerName, line.hasOption('r')); } //if (line.hasOption("container")) if (line.hasOption("object")) { String ObjectNameWithPath = null; ObjectNameWithPath = line.getOptionValue("object"); removeObject(ObjectNameWithPath); } //if (line.hasOption("container")) } //end try catch (ParseException err) { logger.fatal("Parsing exception on the command line: " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (Exception err) { logger.fatal("Exception : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:ie.peternagy.jcrypto.cli.JCryptoCli.java
public static void main(String[] args) { long startTime = System.currentTimeMillis(); try {//from ww w. ja v a 2 s. c o m CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(OPTIONS, args); isVerbose = line.hasOption('v'); routeParams(line); if (isVerbose) { System.out.printf("\n Process finished in %dms\n\n", System.currentTimeMillis() - startTime); } } catch (org.apache.commons.cli.ParseException ex) { printCliHelp(); //@todo: override the logger if not in debug mode Logger.getLogger(JCryptoCli.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:be.i8c.sag.wm.is.SwaggerImporter.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); Options options = getOptions();//from w ww . j a va2s .co m CommandLine cmd = parser.parse(options, args); HelpFormatter formatter = new HelpFormatter(); if (cmd.hasOption("h")) { formatter.printHelp("", options); } else if (cmd.hasOption("is") && cmd.hasOption("u") && cmd.hasOption("p") && cmd.hasOption("swf") && cmd.hasOption("pkg")) { SwaggerParser swaggerParser = new SwaggerParser(); Swagger swaggerModel = swaggerParser.read(cmd.getOptionValue("swf")); String[] conn = cmd.getOptionValue("is").split(":"); String host = conn[0]; String port = "80"; if (conn.length > 1) { port = conn[1]; } ServerConnection sc = new ServerConnection(host, port, cmd.getOptionValue("u"), cmd.getOptionValue("p"), false); try { logger.info("Connecting to server " + host + "(" + port + ")"); sc.connect(); logger.info("Connected to server"); RestImplementation ri = new RestImplementation(sc, swaggerModel, cmd.getOptionValue("pkg"), cmd.getOptionValue("acl")); ri.generateImplementation(); } catch (Throwable e) { logger.error("Error: " + e.getMessage()); //logger.error(e.getStackTrace()); e.printStackTrace(); } finally { logger.info("Disconnecting from server"); sc.disconnect(); ServerConnectionManager.getInstance().closeServerConnectionManager(); logger.info("Disconnected from server"); logger.info("BYE"); System.exit(0); } } }