List of usage examples for org.apache.commons.cli ParseException ParseException
public ParseException(String message)
ParseException
with the specified detail message. From source file:de.fischer.thotti.core.runner.TargetURLGenerator.java
public static final void main(String[] args) { String accessKey = null;/*from ww w. ja va 2 s . c om*/ String secretKey = null; Options options = createCommandLineOption(); CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (!line.hasOption("ak")) { throw new ParseException("AWS Accress Key is missing."); } if (!line.hasOption("sk")) { throw new ParseException("AWS Secret Key is missing."); } accessKey = line.getOptionValue("ak"); secretKey = line.getOptionValue("sk"); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); System.exit(1); } TargetURLGenerator generator = new TargetURLGenerator(); generator.setAccessKey(accessKey); generator.setSecretKey(secretKey); generator.run(); }
From source file:com.etsy.arbiter.Arbiter.java
public static void main(String[] args) throws ParseException, ConfigurationException, IOException, ParserConfigurationException, TransformerException { Options options = getOptions();//from w w w. j av a 2 s .c o m CommandLineParser cmd = new GnuParser(); CommandLine parsed = cmd.parse(options, args); if (parsed.hasOption("h")) { printUsage(options); } if (!parsed.hasOption("i")) { throw new ParseException("Missing required argument: i"); } if (!parsed.hasOption("o")) { throw new ParseException("Missing required argument: o"); } String[] configFiles = parsed.getOptionValues("c"); String[] lowPrecedenceConfigFiles = parsed.getOptionValues("l"); String[] inputFiles = parsed.getOptionValues("i"); String outputDir = parsed.getOptionValue("o"); List<Config> parsedConfigFiles = readConfigFiles(configFiles, false); parsedConfigFiles.addAll(readConfigFiles(lowPrecedenceConfigFiles, true)); Config merged = ConfigurationMerger.mergeConfiguration(parsedConfigFiles); List<Workflow> workflows = readWorkflowFiles(inputFiles); boolean generateGraphviz = parsed.hasOption("g"); String graphvizFormat = parsed.getOptionValue("g", "svg"); OozieWorkflowGenerator generator = new OozieWorkflowGenerator(merged); generator.generateOozieWorkflows(outputDir, workflows, generateGraphviz, graphvizFormat); }
From source file:com.redhat.akashche.keystoregen.Launcher.java
public static void main(String[] args) throws Exception { try {// w w w . ja va 2 s . co m 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 (0 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION) && cline.hasOption(OUTPUT_OPTION)) { KeystoreConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION)); KeyStore ks = new KeystoreGenerator().generate(conf); writeKeystore(conf, ks, 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 keystoregen.jar -c config.json -o output.p12", OPTIONS); } }
From source file:com.trovit.hdfstree.HdfsTree.java
public static void main(String... args) { Options options = new Options(); options.addOption("l", false, "Use local filesystem."); options.addOption("p", true, "Path used as root for the tree."); options.addOption("s", false, "Display the size of the directory"); options.addOption("d", true, "Maximum depth of the tree (when displaying)"); CommandLineParser parser = new PosixParser(); TreeBuilder treeBuilder;// ww w . j a v a 2s . c o m FSInspector fsInspector = null; String rootPath = null; Displayer displayer = new ConsoleDisplayer(); try { CommandLine cmd = parser.parse(options, args); // local or hdfs. if (cmd.hasOption("l")) { fsInspector = new LocalFSInspector(); } else { fsInspector = new HDFSInspector(); } // check that it has the root path. if (cmd.hasOption("p")) { rootPath = cmd.getOptionValue("p"); } else { throw new ParseException("Mandatory option (-p) is not specified."); } if (cmd.hasOption("d")) { displayer.setMaxDepth(Integer.parseInt(cmd.getOptionValue("d"))); } if (cmd.hasOption("s")) { displayer.setDisplaySize(); } } catch (ParseException e) { System.out.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("hdfstree", options); System.exit(1); } treeBuilder = new TreeBuilder(rootPath, fsInspector); TreeNode tree = treeBuilder.buildTree(); displayer.display(tree); }
From source file:io.proscript.jlight.JLight.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); Option host = new Option("h", "host", true, "Host of the HTTP server (default 127.0.0.1)"); Option port = new Option("p", "port", true, "Port of the HTTP server (default 9000)"); Option main = new Option("c", "class", true, "Application to run, e.g. org.vendor.class"); Option help = new Option("h", "help", false, "Display help and exit"); Option version = new Option("v", "version", false, "Display JLight version"); options.addOption(host);//from ww w.ja va 2 s. co m options.addOption(port); options.addOption(main); options.addOption(help); options.addOption(version); CommandLine line; try { line = parser.parse(options, args); if (line.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); Version.print(); formatter.printHelp("jlight", options); return; } if (line.hasOption("v")) { Version.print(); return; } if (!line.hasOption("c")) { throw new ParseException("Option 'class' is required"); } Runtime.run(line); } catch (ParseException exp) { System.err.println(exp.getMessage()); } }
From source file:com.github.jasmo.Bootstrap.java
public static void main(String[] args) { Options options = new Options().addOption("h", "help", false, "Print help message") .addOption("v", "verbose", false, "Increase verbosity") .addOption("c", "cfn", true, "Enable 'crazy fucking names and set name length (large names == large output size)'") .addOption("p", "package", true, "Move obfuscated classes to this package") .addOption("k", "keep", true, "Don't rename this class"); try {//from w w w . j a v a 2s .c o m CommandLineParser clp = new DefaultParser(); CommandLine cl = clp.parse(options, args); if (cl.hasOption("help")) { help(options); return; } if (cl.hasOption("verbose")) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers(); } String[] keep = cl.getOptionValues("keep"); if (cl.getArgList().size() < 2) { throw new ParseException("Expected at-least two arguments"); } log.debug("Input: {}, Output: {}", cl.getArgList().get(0), cl.getArgList().get(1)); Obfuscator o = new Obfuscator(); try { o.supply(Paths.get(cl.getArgList().get(0))); } catch (Exception e) { log.error("An error occurred while reading the source target", e); return; } try { UniqueStringGenerator usg; if (cl.hasOption("cfn")) { int size = Integer.parseInt(cl.getOptionValue("cfn")); usg = new UniqueStringGenerator.Crazy(size); } else { usg = new UniqueStringGenerator.Default(); } o.apply(new FullAccessFlags()); o.apply(new ScrambleStrings()); o.apply(new ScrambleClasses(usg, cl.getOptionValue("package", ""), keep == null ? new String[0] : keep)); o.apply(new ScrambleFields(usg)); o.apply(new ScrambleMethods(usg)); o.apply(new InlineAccessors()); o.apply(new RemoveDebugInfo()); o.apply(new ShuffleMembers()); } catch (Exception e) { log.error("An error occurred while applying transform", e); return; } try { o.write(Paths.get(cl.getArgList().get(1))); } catch (Exception e) { log.error("An error occurred while writing to the destination target", e); return; } } catch (ParseException e) { log.error("Failed to parse command line arguments", e); help(options); } }
From source file:it.tizianofagni.sparkboost.BoostClassifierExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("p", "parallelismDegree", true, "Set the parallelism degree (default: number of available cores in the Spark runtime"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;//from w ww .ja v a2s. co m String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 3) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( BoostClassifierExe.class.getSimpleName() + " [OPTIONS] <inputFile> <inputModel> <outputFile>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String inputModel = remainingArgs[1]; String outputFile = remainingArgs[2]; long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark MPBoost classifier"); JavaSparkContext sc = new JavaSparkContext(conf); // Load boosting classifier from disk. BoostClassifier classifier = DataUtils.loadModel(sc, inputModel); // Get the parallelism degree. int parallelismDegree = sc.defaultParallelism(); if (cmd.hasOption("p")) { parallelismDegree = Integer.parseInt(cmd.getOptionValue("p")); } // Classify documents available on specified input file. classifier.classifyLibSvm(sc, inputFile, parallelismDegree, labels0Based, binaryProblem, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }
From source file:net.forkwait.imageautomator.ImageAutomator.java
public static void main(String[] args) throws IOException { String inputImage = ""; Options options = new Options(); options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext"); options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97"); options.addOption("s", true, "output max side length in px (e.g. 800), default 1200"); options.addOption("w", true, "watermark image file"); options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0"); options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT"); /*/* ww w . j a va 2s . c o m*/ TOP_LEFT TOP_CENTER TOP_RIGHT CENTER_LEFT CENTER CENTER_RIGHT BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT */ CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { throw new ParseException("Too few arguments"); } else if (cmd.getArgs().length > 1) { throw new ParseException("Too many arguments"); } inputImage = cmd.getArgs()[0]; } catch (ParseException e) { showHelp(options, e.getLocalizedMessage()); System.exit(-1); } Thumbnails.Builder<File> st = Thumbnails.of(inputImage); if (cmd.hasOption("q")) { st.outputQuality(Double.parseDouble(cmd.getOptionValue("q"))); } else { st.outputQuality(0.97f); } if (cmd.hasOption("s")) { st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s"))); } else { st.size(1200, 1200); } if (cmd.hasOption("w")) { Positions position = Positions.BOTTOM_RIGHT; float trans = 0.5f; if (cmd.hasOption("wp")) { position = Positions.valueOf(cmd.getOptionValue("wp")); } if (cmd.hasOption("wt")) { trans = Float.parseFloat(cmd.getOptionValue("wt")); } st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans); } if (cmd.hasOption("o")) { st.toFile(new File(cmd.getOptionValue("o"))); } else { st.toFiles(Rename.PREFIX_DOT_THUMBNAIL); } //.outputFormat("jpg") System.exit(0); }
From source file:it.tizianofagni.sparkboost.MPBoostLearnerExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("dp", "documentPartitions", true, "The number of document partitions"); options.addOption("fp", "featurePartitions", true, "The number of feature partitions"); options.addOption("lp", "labelPartitions", true, "The number of label partitions"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;//from w w w. jav a 2s. co m String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 3) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( MPBoostLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String outputFile = remainingArgs[1]; int numIterations = Integer.parseInt(remainingArgs[2]); long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark MPBoost learner"); JavaSparkContext sc = new JavaSparkContext(conf); // Create and configure learner. MpBoostLearner learner = new MpBoostLearner(sc); learner.setNumIterations(numIterations); if (cmd.hasOption("dp")) { learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp"))); } if (cmd.hasOption("fp")) { learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp"))); } if (cmd.hasOption("lp")) { learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp"))); } // Build classifier with MPBoost learner. BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem); // Save classifier to disk. DataUtils.saveModel(sc, classifier, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }
From source file:it.tizianofagni.sparkboost.AdaBoostMHLearnerExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("dp", "documentPartitions", true, "The number of document partitions"); options.addOption("fp", "featurePartitions", true, "The number of feature partitions"); options.addOption("lp", "labelPartitions", true, "The number of label partitions"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;/*from w w w.jav a 2 s . co m*/ String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 5) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(AdaBoostMHLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations> <sparkMaster> <parallelismDegree>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String outputFile = remainingArgs[1]; int numIterations = Integer.parseInt(remainingArgs[2]); String sparkMaster = remainingArgs[3]; int parallelismDegree = Integer.parseInt(remainingArgs[4]); long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark AdaBoost.MH learner"); JavaSparkContext sc = new JavaSparkContext(conf); // Create and configure learner. AdaBoostMHLearner learner = new AdaBoostMHLearner(sc); learner.setNumIterations(numIterations); if (cmd.hasOption("dp")) { learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp"))); } if (cmd.hasOption("fp")) { learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp"))); } if (cmd.hasOption("lp")) { learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp"))); } // Build classifier with MPBoost learner. BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem); // Save classifier to disk. DataUtils.saveModel(sc, classifier, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }