@Override void run(String[] args) { try { CommandLine cli = parseOptions(args); if (!paramsAreValid(cli)) { return; } int numKeys = Integer.parseInt(cli.getOptionValue(NUM_KEYS.getOpt(), "20")); char[] password = getPasswordFromConsole(); String keystoreLocation = cli.getOptionValue(KEYSTORE_LOCATION.getOpt()); JCEKSKeystoreCredentialStore credentialStore = new JCEKSKeystoreCredentialStore(cli.getOptionValue(KEYSTORE_LOCATION.getOpt()), String.valueOf(password), EnumSet.of(JCEKSKeystoreCredentialStore.CreationOptions.CREATE_IF_MISSING)); credentialStore.generateAesKeys(numKeys, 0); System.out.println("Generated " + String.valueOf(numKeys) + " keys at " + keystoreLocation); } catch (IOException | KeyStoreException e) { throw new RuntimeException(e); } catch (ParseException e) { System.out.println("Unknown command line params " + e.toString()); printUsage(); } }
public static CommandLine processCommandLineArgs(String[] cliArgs, Options cliOptions) throws Exception { CommandLineParser cliParser = new GnuParser(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; } }
public static CommandLine processCommandLineArgs(String[] cliArgs, Options cliOptions) throws Exception { CommandLineParser cliParser = new GnuParser(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; } }
public static CommandLine processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }
public static CommandLine processCommandLineArgs(String[] cliArgs) { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); // CommandLine cmd = null; try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }
protected int parseOptions(final String[] args) throws MalformedURLException { CommandLineParser parser = new GnuParser(); try { cmdLine = parser.parse(options, args); if ( cmdLine.hasOption("h") ) { url = new URL(cmdLine.getOptionValue("h")); } if ( cmdLine.hasOption("u") ) { username = cmdLine.getOptionValue("u"); } if ( cmdLine.hasOption("p") ) { password = cmdLine.getOptionValue("p"); } if( url == null ) { printHelp(options); return -1; } } catch (ParseException e) { LOGGER.error("Unable to parse the options ({})", e.toString()); LOGGER.debug(e.toString(), e); return 1; } return 0; }
public static CommandLine processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }
public static CommandLine processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }
public static CommandLine processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }
public static CommandLine processCommandLineArgs(String[] cliArgs) { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); // CommandLine cmd = null; try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }
private Map<String, Object> parseArgumentsRun(final String... args) { if (args.length > 0) { try { Options options = new Options(); options.addOption("connectionFile", true, "Connection File Path"); options.addOption("verbose", true, "Verbose Mode"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); Map<String, Object> parameters = new HashMap<>(); parameters.put("connectionFile", cmd.getOptionValue("connectionFile")); parameters.put("logLevel", cmd.getOptionValue("verbose")); return parameters; } catch (ParseException ex) { log.error("Error parsing arguments : " + ex.toString()); } } else { log.error("No parameters passed to the Scijava kernel."); } return null; }
private static CommandLine parseCommandLine(String args[], String opts[][]) throws MuleException { Options options = new Options(); for (String[] opt : opts) { options.addOption(opt[0], opt[1].equals("true") ? true : false, opt[2]); } BasicParser parser = new BasicParser(); try { CommandLine line = parser.parse(options, args, true); if (line == null) { throw new DefaultMuleException("Unknown error parsing the Mule command line"); } return line; } catch (ParseException p) { throw new DefaultMuleException("Unable to parse the Mule command line because of: " + p.toString(), p); } }
/** Attempts to parse options for given command, printing usage under failure */ private static CommandLine parseOptions(String[] args, Options options, String cmdStr) { CommandLineParser cliParser = new GnuParser(); CommandLine cmd = null; try { cmd = cliParser.parse(options, args); } catch (ParseException pe) { LOG.error("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(options, cmdStr); System.exit(1); } boolean ret = checkOptionArgsNumber(cmd.getOptions()); if (!ret) { printUsage(options, cmdStr); System.exit(1); } return cmd; }
private static CommandLine parseCommandLine(String args[], String opts[][]) throws DefaultMuleException { Options options = new Options(); for (int i = 0; i < opts.length; i++) { options.addOption(opts[i][0], opts[i][1].equals("true") ? true : false, opts[i][2]); } BasicParser parser = new BasicParser(); try { CommandLine line = parser.parse(options, args, true); if (line == null) { throw new DefaultMuleException("Unknown error parsing the Mule command line"); } return line; } catch (ParseException p) { throw new DefaultMuleException("Unable to parse the Mule command line because of: " + p.toString(), p); } }
/** Attempts to parse options for given command, printing usage under failure */ private static CommandLine parseOptions(String[] args, Options options, String cmdStr) { CommandLineParser cliParser = new GnuParser(); CommandLine cmd = null; try { cmd = cliParser.parse(options, args); } catch (ParseException pe) { LOG.error("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(options, cmdStr); System.exit(1); } boolean ret = checkOptionArgsNumber(cmd.getOptions()); if (!ret) { printUsage(options, cmdStr); System.exit(1); } return cmd; }
@Override void run(String[] args) { try { CommandLine cli = parseOptions(args); if (!paramsAreValid(cli)) { return; } int numKeys = Integer.parseInt(cli.getOptionValue(NUM_KEYS.getOpt(), "20")); char[] password = getPasswordFromConsole(); String keystoreLocation = cli.getOptionValue(KEYSTORE_LOCATION.getOpt()); JCEKSKeystoreCredentialStore credentialStore = new JCEKSKeystoreCredentialStore(cli.getOptionValue(KEYSTORE_LOCATION.getOpt()), String.valueOf(password), EnumSet.of(JCEKSKeystoreCredentialStore.CreationOptions.CREATE_IF_MISSING)); credentialStore.generateAesKeys(numKeys, 0); System.out.println("Generated " + String.valueOf(numKeys) + " keys at " + keystoreLocation); } catch (IOException | KeyStoreException e) { throw new RuntimeException(e); } catch (ParseException e) { System.out.println("Unknown command line params " + e.toString()); printUsage(); } }
@SuppressWarnings("unchecked") public int mknode(String[] args) { Options mknodeOption = new Options(); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(mknodeOption, args); List<String> argsList = line.getArgList(); if (argsList.size() != 2) { return usageError("mknode requires exactly one path argument", MKNODE_USAGE); } if (!validatePath(argsList.get(1))) { return -1; } try { registry.mknode(args[1], false); return 0; } catch (Exception e) { syserr.println(analyzeException("mknode", e, argsList)); } return -1; } catch (ParseException exp) { return usageError("Invalid syntax " + exp.toString(), MKNODE_USAGE); } }
public static void processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); CommandLine cmd = null; try { cmd = cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("RestAdminApplication: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } int port = DEFAULT_PORT; if (cmd.hasOption(HELP)) { printUsage(cliOptions); return; } else if (cmd.hasOption(PORT)) { port = Integer.parseInt(cmd.getOptionValue(PORT)); } HelixAdminWebApp app = new HelixAdminWebApp(cmd.getOptionValue(ZKSERVERADDRESS), port); app.start(); try { Thread.currentThread().join(); } finally { app.stop(); } }
@SuppressWarnings("unchecked") public int mknode(String[] args) { Options mknodeOption = new Options(); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(mknodeOption, args); List<String> argsList = line.getArgList(); if (argsList.size() != 2) { return usageError("mknode requires exactly one path argument", MKNODE_USAGE); } if (!validatePath(argsList.get(1))) { return -1; } try { registry.mknode(args[1], false); return 0; } catch (Exception e) { syserr.println(analyzeException("mknode", e, argsList)); } return -1; } catch (ParseException exp) { return usageError("Invalid syntax " + exp.toString(), MKNODE_USAGE); } }
public static CommandLine processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); // CommandLine cmd = null; try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; }