本文整理匯總了Java中org.kohsuke.args4j.CmdLineException類的典型用法代碼示例。如果您正苦於以下問題:Java CmdLineException類的具體用法?Java CmdLineException怎麽用?Java CmdLineException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CmdLineException類屬於org.kohsuke.args4j包,在下文中一共展示了CmdLineException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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);
}
}
}
示例2: init
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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);
}
}
}
示例3: invalidJsonForDiscoveryFilter
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
@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);
}
示例4: create
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
/**
* 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;
}
示例5: main
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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();
}
}
示例6: main
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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();
}
示例7: main
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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();
}
示例8: doMain
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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 + "'.");
}
示例9: main
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
/**
* @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;
}
}
示例10: parse
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
/** 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;
}
示例11: doMain
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
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);
}
}
示例12: getParameters
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
/**
* 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;
}
示例13: parseArguments
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
@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;
}
示例14: testRunError
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
@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"));
}
}
示例15: testStepEmpty
import org.kohsuke.args4j.CmdLineException; //導入依賴的package包/類
@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"));
}
}