use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
the class VerifiableConsumer method main.
public static void main(String[] args) {
ArgumentParser parser = argParser();
if (args.length == 0) {
parser.printHelp();
Exit.exit(0);
}
try {
final VerifiableConsumer consumer = createFromArgs(parser, args);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
consumer.close();
}
});
consumer.run();
} catch (ArgumentParserException e) {
parser.handleError(e);
Exit.exit(1);
}
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project kafka by apache.
the class VerifiableProducer method createFromArgs.
/** Construct a VerifiableProducer object from command-line arguments. */
public static VerifiableProducer createFromArgs(String[] args) {
ArgumentParser parser = argParser();
VerifiableProducer producer = null;
try {
Namespace res;
res = parser.parseArgs(args);
int maxMessages = res.getInt("maxMessages");
String topic = res.getString("topic");
int throughput = res.getInt("throughput");
String configFile = res.getString("producer.config");
Integer valuePrefix = res.getInt("valuePrefix");
Properties producerProps = new Properties();
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, res.getString("brokerList"));
producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
producerProps.put(ProducerConfig.ACKS_CONFIG, Integer.toString(res.getInt("acks")));
// No producer retries
producerProps.put("retries", "0");
if (configFile != null) {
try {
producerProps.putAll(loadProps(configFile));
} catch (IOException e) {
throw new ArgumentParserException(e.getMessage(), parser);
}
}
producer = new VerifiableProducer(producerProps, topic, throughput, maxMessages, valuePrefix);
} catch (ArgumentParserException e) {
if (args.length == 0) {
parser.printHelp();
Exit.exit(0);
} else {
parser.handleError(e);
Exit.exit(1);
}
}
return producer;
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project helios by spotify.
the class DeploymentGroupInspectCommandTest method setUp.
@Before
public void setUp() {
// use a real, dummy Subparser impl to avoid having to mock out every single call
final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
final Subparser subparser = parser.addSubparsers().addParser("inspect");
command = new DeploymentGroupInspectCommand(subparser);
when(client.deploymentGroup(NAME)).thenReturn(Futures.immediateFuture(DEPLOYMENT_GROUP));
final ListenableFuture<DeploymentGroup> nullFuture = Futures.immediateFuture(null);
when(client.deploymentGroup(NON_EXISTENT_NAME)).thenReturn(nullFuture);
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project helios by spotify.
the class HostListCommandTest method runCommand.
private int runCommand(String... commandArgs) throws ExecutionException, InterruptedException, ArgumentParserException {
final String[] args = new String[1 + commandArgs.length];
args[0] = "hosts";
System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);
// use a real, dummy Subparser impl to avoid having to mock out every single call
final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
final Subparser subparser = parser.addSubparsers().addParser("hosts");
final HostListCommand command = new HostListCommand(subparser);
final Namespace options = parser.parseArgs(args);
return command.run(options, client, out, false, null);
}
use of net.sourceforge.argparse4j.inf.ArgumentParser in project helios by spotify.
the class HostRegisterCommandTest method setUp.
@Before
public void setUp() {
// use a real, dummy Subparser impl to avoid having to mock out every single call
final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
final Subparser subparser = parser.addSubparsers().addParser("register");
command = new HostRegisterCommand(subparser);
}
Aggregations