Search in sources :

Example 11 with ArgumentParser

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);
    }
}
Also used : ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser)

Example 12 with ArgumentParser

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;
}
Also used : IOException(java.io.IOException) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) Properties(java.util.Properties) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 13 with ArgumentParser

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);
}
Also used : Subparser(net.sourceforge.argparse4j.inf.Subparser) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Before(org.junit.Before)

Example 14 with ArgumentParser

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);
}
Also used : Subparser(net.sourceforge.argparse4j.inf.Subparser) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 15 with ArgumentParser

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);
}
Also used : Subparser(net.sourceforge.argparse4j.inf.Subparser) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Before(org.junit.Before)

Aggregations

ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)20 Subparser (net.sourceforge.argparse4j.inf.Subparser)8 Before (org.junit.Before)7 Namespace (net.sourceforge.argparse4j.inf.Namespace)6 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)5 Properties (java.util.Properties)3 IOException (java.io.IOException)2 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)2 Supplier (com.google.common.base.Supplier)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)1 JobId (com.spotify.helios.common.descriptors.JobId)1 JobStatus (com.spotify.helios.common.descriptors.JobStatus)1 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 RoundRobinAssignor (org.apache.kafka.clients.consumer.RoundRobinAssignor)1