本文整理了Java中org.apache.commons.cli.ParseException.toString()
方法的一些代码示例,展示了ParseException.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ParseException.toString()
方法的具体详情如下:
包路径:org.apache.commons.cli.ParseException
类名称:ParseException
方法名:toString
暂无
代码示例来源:origin: apache/incubator-gobblin
@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();
}
}
代码示例来源:origin: apache/helix
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;
}
}
代码示例来源:origin: org.apache.helix/helix-core
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;
}
}
代码示例来源:origin: org.apache.helix/helix-core
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;
}
代码示例来源:origin: apache/helix
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;
}
代码示例来源:origin: lsc-project/lsc
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;
}
代码示例来源:origin: apache/helix
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;
}
代码示例来源:origin: org.apache.helix/helix-core
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;
}
代码示例来源:origin: apache/helix
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;
}
代码示例来源:origin: org.apache.helix/helix-core
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;
}
代码示例来源:origin: scijava/scijava-jupyter-kernel
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;
}
代码示例来源:origin: org.mule.runtime/mule-core
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);
}
}
代码示例来源:origin: org.apache.helix/helix-core
/** 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;
}
代码示例来源:origin: org.mule/mule-core
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);
}
}
代码示例来源:origin: apache/helix
/** 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;
}
代码示例来源:origin: org.apache.gobblin/gobblin-crypto-provider
@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();
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry
@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);
}
}
代码示例来源:origin: apache/helix
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();
}
}
代码示例来源:origin: io.hops/hadoop-yarn-registry
@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);
}
}
代码示例来源:origin: apache/helix
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;
}
内容来源于网络,如有侵权,请联系作者删除!