protected void init(String[] args) { try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); parser.printUsage(System.err); System.exit(1); } if (help) { parser.printUsage(System.err); System.exit(1); } if (!AuthScheme.NO_AUTH.equals(authScheme)) { if (keyStorePath == null) { System.err.println("keyStorePath is required when " + "authScheme is " + authScheme); parser.printUsage(System.err); System.exit(1); } if (keyStorePassword == null) { Console con = System.console(); char[] password = con.readPassword("Enter key store password: "); keyStorePassword = new String(password); } } }
@Test public void invalidJsonForDiscoveryFilter() throws CmdLineException, ConfigurationException { OFEventWFMTopology manager = new OFEventWFMTopology(makeLaunchEnvironment()); TopologyConfig config = manager.getConfig(); OFELinkBolt bolt = new OFELinkBolt(config); TopologyContext context = Mockito.mock(TopologyContext.class); Mockito.when(context.getComponentId(TASK_ID_BOLT)) .thenReturn(COMPONENT_ID_SOURCE); Mockito.when(context.getComponentOutputFields(COMPONENT_ID_SOURCE, STREAM_ID_INPUT)) .thenReturn(KafkaMessage.FORMAT); OutputCollectorMock outputDelegate = Mockito.spy(new OutputCollectorMock()); OutputCollector output = new OutputCollector(outputDelegate); bolt.prepare(stormConfig(), context, output); bolt.initState(new InMemoryKeyValueState<>()); Tuple tuple = new TupleImpl(context, new Values("{\"corrupted-json"), TASK_ID_BOLT, STREAM_ID_INPUT); bolt.doWork(tuple); Mockito.verify(outputDelegate).ack(tuple); }
/** * Parse the CLI arguments and return the populated parameters structure. * * @param args the CLI arguments * @return the parsed parameters, or null if failed * @throws org.kohsuke.args4j.CmdLineException if cmd line is malformed */ public static CLI create (final String... args) throws CmdLineException { logger.info("CLI args: {}", Arrays.toString(args)); CLI cli = new CLI(); final CmdLineParser parser = new CmdLineParser(cli); parser.parseArgument(args); if (args.length == 0) { cli.help = true; } if (cli.help) { printUsage(parser); } return cli; }
public static void main(final String[] args) { try { final MainArgs mainArgs = new MainArgs(); new CmdLineParser(mainArgs).parseArgument(args); if (mainArgs.isHelp()) { printUsage(); } else if (mainArgs.isVersion()) { printVersion(); } else { Guice.createInjector(new EndPointHealthModule()) .getInstance(Main.class).run(mainArgs); } } catch (final CmdLineException e) { System.err.println(e.getMessage()); printUsage(); } }
public static void main(String[] args) throws IOException { Consumer consumer = new Consumer(); CmdLineParser parser = new CmdLineParser(consumer); try { parser.parseArgument(args); } catch (CmdLineException ce) { System.err.println(ce.getMessage()); System.err.println(); System.err.println(" Options are:"); parser.printUsage(System.err); // print the list of available options System.err.println(); System.exit(0); } consumer.run(); }
public static void main(String[] args) throws IOException { Producer producer = new Producer(); CmdLineParser parser = new CmdLineParser(producer); try { parser.parseArgument(args); } catch (CmdLineException ce) { System.err.println(ce.getMessage()); System.err.println(); System.err.println(" Options are:"); parser.printUsage(System.err); // print the list of available options System.err.println(); System.exit(0); } producer.run(); }
private void doMain(final String[] arguments) throws IOException { final CmdLineParser parser = new CmdLineParser(this); if (arguments.length < 1) { parser.printUsage(out); System.exit(-1); } try { parser.parseArgument(arguments); } catch (CmdLineException clEx) { out.println("ERROR: Unable to parse command-line options: " + clEx); } out.println("The file '" + fileName + "' was provided and verbosity is set to '" + verbose + "'."); }
/** * @return success value */ public static boolean main(String[] args) throws IOException, InterruptedException, URISyntaxException { PrintWriter writer = new PrintWriter(System.out, true); CliArgs arguments = new CliArgs(); try { if (!arguments.parse(writer, args)) { return true; } if(arguments.isModeParse()) { parse(arguments); return true; } else { return diff(writer, arguments); } } catch (CmdLineException | NotAllowedObjectException ex) { System.err.println(ex.getLocalizedMessage()); return false; } }
/** Parse the command line options. * @param args the command line args as passed to the main method of the * program. * @return the parsed command line options or {@code null} if * the program needs to exit. {@code null} will be returned * if the command lines are wrong or the command line help * was displayed. */ public static Params parse(String[] args) { Params result = new Params(); CmdLineParser cmdLineParser = new CmdLineParser(result); try { if (log.isDebugEnabled()) { log.debug("Args: {}", Arrays.toString(args)); } cmdLineParser.parseArgument(args); if (result.help) { cmdLineParser.printUsage(System.err); return null; } return result; } catch (CmdLineException ex) { log.warn("Error in parsing", ex); System.err.println(ex.getMessage()); cmdLineParser.printUsage(System.err); } return null; }
private void doMain( String[] args) { CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); ensureResultXmlDirectory(); generateDonutJsonFiles(); }catch (CmdLineException c){ System.err.println(c.getMessage()); System.err.println("usage: Main [options ...]"); parser.printUsage(System.err); System.exit(1); }catch (Exception e) { System.err.println(e.getMessage()); System.exit(1); } }
/** * Parse the CLI arguments and return the populated parameters structure. * * @param args the CLI arguments * @return the parsed parameters, or null if failed * @throws org.kohsuke.args4j.CmdLineException */ public Parameters getParameters (final String... args) throws CmdLineException { logger.info("CLI args: {}", Arrays.toString(args)); actualArgs = args; parser.parseArgument(args); if (logger.isDebugEnabled()) { new Dumping().dump(params); } checkParams(); return params; }
@Override public int parseArguments (org.kohsuke.args4j.spi.Parameters params) throws CmdLineException { String className = params.getParameter(0).trim(); if (!className.isEmpty()) { try { Class runClass = Class.forName(className); FieldSetter fs = setter.asFieldSetter(); fs.addValue(runClass); } catch (Throwable ex) { throw new CmdLineException(owner, ex); } } return 1; }
@Override public int parseArguments (org.kohsuke.args4j.spi.Parameters params) throws CmdLineException { String name = params.getParameter(-1); String pair = params.getParameter(0); FieldSetter fs = setter.asFieldSetter(); Properties props = (Properties) fs.getValue(); if (props == null) { props = new Properties(); fs.addValue(props); } try { props.load(new StringReader(pair)); } catch (Exception ex) { throw new CmdLineException(owner, "Error in " + name + " " + pair, ex); } return 1; }
@Test public void testRunError () throws Exception { System.out.println("\n+++ testRunError"); String[] args = new String[]{"-run", "fooBar"}; try { CLI.Parameters params = instance.getParameters(args); fail(); } catch (CmdLineException ex) { System.out.println(ex.getMessage()); System.out.println(ex.getLocalizedMessage()); assertTrue(ex.getMessage().contains("java.lang.ClassNotFoundException")); } }
@Test public void testStepEmpty () throws Exception { System.out.println("\n+++ testStepEmpty"); String[] args = new String[]{"-step"}; try { CLI.Parameters params = instance.getParameters(args); fail(); } catch (CmdLineException ex) { System.out.println(ex.getMessage()); System.out.println(ex.getLocalizedMessage()); assertTrue(ex.getMessage().contains("-step")); } }
private void parseArguments(String[] args) { CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); } catch (CmdLineException e) { // if there's a problem in the command line, // you'll get this exception. this will report // an error message. System.err.println(e.getMessage()); System.err.println("java -jar reddit-history.jar [options...] arguments..."); // print the list of available options parser.printUsage(System.err); System.err.println(); System.exit(0); return; } }
/** * Parse the command line into the specified configuration. * * @param args The command line. * @param config The configuration class. * @return true if successful, false on errors such as missing arguments. */ private boolean parseCommandLine(String[] args, Configuration config) { CmdLineParser parser = new CmdLineParser(config); try { parser.parseArgument(args); if (config.getRemainingArguments() == null || config.getRemainingArguments().isEmpty()) { printUsage(parser); return false; } else { return true; } } catch (CmdLineException e) { printUsage(parser); System.out.println("Error: " + e.getMessage()); return false; } }
private void parseArguments(String[] args) { CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); } catch (CmdLineException e) { // if there's a problem in the command line, // you'll get this exception. this will report // an error message. System.err.println(e.getMessage()); System.err.println("java -jar torfiles.jar [options...] arguments..."); // print the list of available options parser.printUsage(System.err); System.err.println(); System.exit(0); return; } }
public static void main(String[] args) throws IOException { final MultiEntitySinkConfig config = new MultiEntitySinkConfig(); final CmdLineParser cmdLineParser = new CmdLineParser(config); try { cmdLineParser.parseArgument(args); final OsmosisReader reader = new OsmosisReader(newInputStream(config.getSource())); final MultiEntitySink sink = new MultiEntitySink(config); sink.addObserver(new MultiEntitySinkObserver()); reader.setSink(sink); reader.run(); } catch (CmdLineException e) { System.out.println(e.getMessage()); System.out.print("Usage: java -jar osm-parquetizer.jar"); System.out.println(); cmdLineParser.printSingleLineUsage(System.out); } }
private void processArgs(String[] args) throws CmdLineException { CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); if (arguments.isEmpty() && (outDir == null || imagecatUrl == null || hostPart == null || pagePrefix == null)){ throw new CmdLineException("Usage Error!"); } // make outputDir if (!outDir.exists() && outDir.isDirectory()){ LOG.info("Creating ["+outDir.getAbsolutePath()+"]"); outDir.mkdirs(); } } catch (CmdLineException e) { System.err.println(e.getMessage()); System.err.println(USAGE); parser.printUsage(System.err); throw e; } }
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException { PersonaExtractor extractor = new PersonaExtractor(); Map<String, Persona> personas = null; Persona persona = null; try { extractor.processArgs(args); String host = extractor.getHost(); if (host == null) { LOG.info("Extracting all personas"); personas = extractor.obtainPersonasForAllHosts(); for (String personaHost : personas.keySet()) { LOG.info("Host: [" + personaHost + "]: Personas: " + personas.get(host).getUsernames()); } } else { persona = extractor.obtainPersonas(extractor.getHost()); LOG.info("Host: [" + host + "]: Personas: " + persona.getUsernames()); } } catch (CmdLineException e) { // don't move on } }
private void processArgs(String[] args) throws CmdLineException { CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); if (arguments.isEmpty() && (pageDir == null || configFile == null || solrUrl == null)) { throw new CmdLineException("Usage Error!"); } } catch (CmdLineException e) { System.err.println(e.getMessage()); System.err.println(USAGE); parser.printUsage(System.err); throw e; } }
public Exporter(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If there are no files, comlain with a non-zero exit code. if (dir == null) System.exit(EX_USAGE); dirPath = FileSystems.getDefault().getPath(dir); }
public ApiBin(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } }
/** * Initialize the verifier, using command-line arguments. * * @param args The command-line arguments passed to the program. */ public RhistMain(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If there are no files, comlain with a non-zero exit code. if (dir == null) System.exit(EX_USAGE); path_ = FileSystems.getDefault().getPath(dir); }
/** * Initialize the verifier, using command-line arguments. * @param args The command-line arguments passed to the program. */ public Verify(String[] args) { final CmdLineParser parser = new CmdLineParser(this, ParserProperties.defaults().withUsageWidth(80)); try { parser.parseArgument(args); } catch (CmdLineException e) { System.err.println(e.getMessage()); print_usage_and_exit_(parser); /* UNREACHABLE */ } // If help is requested, simply print that. if (help) { print_usage_and_exit_(parser); /* UNREACHABLE */ } // If there are no files, comlain with a non-zero exit code. if (files.isEmpty()) System.exit(EX_USAGE); }
public static void main(String[] args) throws IOException { Main m = new Main(); CmdLineParser parser = new CmdLineParser(m); try { parser.parseArgument(args); if (m.filenames.size() == 0) { System.err.println("Usage: pdf2xml [options] <FILEs>"); parser.printUsage(System.err); } else { m.doMain(); } } catch (CmdLineException e) { parser.printUsage(System.err); } }
@Override public int parseArguments(Parameters params) throws CmdLineException { String param = params.getParameter(0); if (param == null) { setter.addValue(true); return 0; } else { String lowerParam = param.toLowerCase(); if (TRUES.contains(lowerParam)) { setter.addValue(true); } else if (FALSES.contains(lowerParam)) { setter.addValue(false); } else { throw new CmdLineException(owner, "Illegal boolean value: " + lowerParam); } return 1; } }
private Node parse(String[] original) { String[] argStrings = args.toArray(new String[] {}); CommandLineRunner runner = null; try { runner = new CommandLineRunner(argStrings); } catch (CmdLineException e) { throw new RuntimeException(e); } Compiler compiler = runner.createCompiler(); JSSourceFile[] inputs = new JSSourceFile[original.length]; for (int i = 0; i < inputs.length; i++) { inputs[i] = JSSourceFile.fromCode("input" + i, original[i]); } compiler.init(externs, inputs, new CompilerOptions()); Node all = compiler.parseInputs(); Node n = all.getLastChild(); return n; }
public void setup(String[] args) { CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); if (showUsage) { System.err.println(versionString); System.err.println("Usage:"); parser.printUsage(System.err); System.exit(0); } } catch (CmdLineException e) { System.err.println("ERROR: " + e.getMessage()); System.err.println("Usage:"); parser.printUsage(System.err); System.exit(1); } tools.INDEX_DIRECTORY_NAME = index_location; }