Search in sources :

Example 36 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project atomix by atomix.

the class AtomixAgent method main.

public static void main(String[] args) throws Exception {
    ArgumentType<Node> nodeArgumentType = (ArgumentParser argumentParser, Argument argument, String value) -> {
        String[] address = parseAddress(value);
        return Node.builder(parseNodeId(address)).withType(Node.Type.CORE).withEndpoint(parseEndpoint(address)).build();
    };
    ArgumentType<Node.Type> typeArgumentType = (ArgumentParser argumentParser, Argument argument, String value) -> Node.Type.valueOf(value.toUpperCase());
    ArgumentType<File> fileArgumentType = (ArgumentParser argumentParser, Argument argument, String value) -> new File(value);
    ArgumentParser parser = ArgumentParsers.newArgumentParser("AtomixServer").defaultHelp(true).description("Atomix server");
    parser.addArgument("node").type(nodeArgumentType).nargs("?").metavar("NAME:HOST:PORT").setDefault(Node.builder("local").withType(Node.Type.CORE).withEndpoint(new Endpoint(InetAddress.getByName("127.0.0.1"), NettyMessagingService.DEFAULT_PORT)).build()).help("The local node info");
    parser.addArgument("--type", "-t").type(typeArgumentType).metavar("TYPE").choices("core", "data", "client").setDefault(Node.Type.CORE).help("Indicates the local node type");
    parser.addArgument("--bootstrap", "-b").nargs("*").type(nodeArgumentType).metavar("NAME:HOST:PORT").required(false).help("Bootstraps a new cluster");
    parser.addArgument("--http-port", "-p").type(Integer.class).metavar("PORT").required(false).setDefault(5678).help("An optional HTTP server port");
    parser.addArgument("--data-dir", "-dd").type(fileArgumentType).metavar("FILE").required(false).setDefault(new File(System.getProperty("user.dir"), "data")).help("The server data directory");
    parser.addArgument("--core-partitions", "-cp").type(Integer.class).metavar("NUM").required(false).setDefault(7).help("The number of core partitions");
    parser.addArgument("--data-partitions", "-dp").type(Integer.class).metavar("NUM").required(false).setDefault(71).help("The number of data partitions");
    Namespace namespace = null;
    try {
        namespace = parser.parseArgs(args);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }
    Node localNode = namespace.get("node");
    Node.Type type = namespace.get("type");
    localNode = Node.builder(localNode.id()).withType(type).withEndpoint(localNode.endpoint()).build();
    List<Node> bootstrap = namespace.getList("bootstrap");
    if (bootstrap == null) {
        bootstrap = Collections.singletonList(localNode);
    }
    File dataDir = namespace.get("data_dir");
    Integer httpPort = namespace.getInt("http_port");
    Integer corePartitions = namespace.getInt("core_partitions");
    Integer dataPartitions = namespace.getInt("data_partitions");
    LOGGER.info("node: {}", localNode);
    LOGGER.info("bootstrap: {}", bootstrap);
    LOGGER.info("data-dir: {}", dataDir);
    Atomix atomix = Atomix.builder().withLocalNode(localNode).withBootstrapNodes(bootstrap).withDataDirectory(dataDir).withCorePartitions(corePartitions).withDataPartitions(dataPartitions).build();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        atomix.stop().join();
    }));
    atomix.start().join();
    LOGGER.info("Atomix listening at {}:{}", localNode.endpoint().host().getHostAddress(), localNode.endpoint().port());
    ManagedRestService rest = RestService.builder().withAtomix(atomix).withEndpoint(Endpoint.from(localNode.endpoint().host().getHostAddress(), httpPort)).build();
    rest.start().join();
    LOGGER.info("HTTP server listening at {}:{}", localNode.endpoint().host().getHostAddress(), httpPort);
    synchronized (Atomix.class) {
        while (atomix.isRunning()) {
            Atomix.class.wait();
        }
    }
}
Also used : Atomix(io.atomix.core.Atomix) Argument(net.sourceforge.argparse4j.inf.Argument) Node(io.atomix.cluster.Node) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ArgumentType(net.sourceforge.argparse4j.inf.ArgumentType) Endpoint(io.atomix.messaging.Endpoint) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ManagedRestService(io.atomix.rest.ManagedRestService) File(java.io.File)

Example 37 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project uuusa by aghie.

the class Samulan method parseCommand.

private static Namespace parseCommand(String[] args) {
    ArgumentParser ap = ArgumentParsers.newArgumentParser("Samulan").defaultHelp(true).description("Apply Sentiment Analysis to files");
    ap.addArgument("-i", "--" + INPUT).required(false).help("Path to the conll file to be analyzed");
    ap.addArgument("-c", "--" + CONLL).required(false).help("Path to a conll file containing the parsed files. " + "You must specify an identifier just above the first conll graph of your text (such as ### IDENTIFIER");
    ap.addArgument("-s", "--" + SENTIDATA).required(true).help("Path to the Sentidata directory");
    ap.addArgument("-e", "--" + ENCODING).setDefault("utf-8").help("Encoding of input data");
    ap.addArgument("-f", "--" + FILTERING).required(false).help("sentistrength to use SentiStrength output. Omit otherwise");
    ap.addArgument("-r", "--" + RULES).help("Path to the .xml file containing the rules");
    ap.addArgument("-o", "--" + OUTPUT).required(false).help("Path to the output file with the predictions");
    ap.addArgument("-v", "--" + VERBOSE).type(Boolean.class).setDefault(false).required(false).help("Print explanation");
    ap.addArgument("-sc", "--" + SCALE).setDefault(TRINARY).help("Selects the type of classification");
    ap.addArgument("-p", "--" + PROPERTIES).required(true).help("Path to the properties file");
    ap.addArgument("-spf", "--" + PATH_SAVED_PARSED_FILE).required(false).help("Path to the file where to saved the parsed sentence in CoNLL format. Useful if you plan to run many experiments");
    Namespace ns = null;
    try {
        // TODO Improve command error checking
        ns = ap.parseArgs(args);
        if (!rawFilesProvided(ns) && !parsedCoNLLFileProvided(ns)) {
            throw new ArgumentParserException(INPUT + " or " + CONLL + " parameter is required", ap);
        }
        if (rawFilesProvided(ns) && parsedCoNLLFileProvided(ns)) {
            throw new ArgumentParserException(INPUT + " or " + CONLL + " cannot appear together required", ap);
        }
        if (ns.get(FILTERING) != null && !ns.get(FILTERING).equals(FILTERING_SENTISTRENGTH)) {
            throw new ArgumentParserException(FILTERING + " not valid", ap);
        }
        if (!ns.get(SCALE).equals(TRINARY) && !ns.get(SCALE).equals(SEMANTIC_ORIENTATION) && !ns.get(SCALE).equals(BINARY)) {
            throw new ArgumentParserException(SCALE + " is not a valid argument. Use: " + SEMANTIC_ORIENTATION + "|" + TRINARY + "|" + BINARY, ap);
        }
    } catch (ArgumentParserException e) {
        ap.handleError(e);
        System.exit(1);
    }
    return ns;
}
Also used : ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Example 38 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 39 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)

Example 40 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project helios by spotify.

the class JobCreateCommandTest 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("create");
    final Supplier<Map<String, String>> envVarSupplier = new Supplier<Map<String, String>>() {

        @Override
        public Map<String, String> get() {
            return ImmutableMap.copyOf(envVars);
        }
    };
    command = new JobCreateCommand(subparser, envVarSupplier);
    when(client.createJob(argThat(matchesName(JOB_NAME)))).thenReturn(immediateFuture(new CreateJobResponse(CreateJobResponse.Status.OK, Collections.<String>emptyList(), "12345")));
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Subparser(net.sourceforge.argparse4j.inf.Subparser) Supplier(com.google.common.base.Supplier) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Before(org.junit.Before)

Aggregations

ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)63 Namespace (net.sourceforge.argparse4j.inf.Namespace)35 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)32 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)13 Subparser (net.sourceforge.argparse4j.inf.Subparser)11 Properties (java.util.Properties)8 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 IOException (java.io.IOException)5 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)5 Path (java.nio.file.Path)4 Collections (java.util.Collections)4 ArgumentParsers (net.sourceforge.argparse4j.ArgumentParsers)4 Subparsers (net.sourceforge.argparse4j.inf.Subparsers)4 Platform (org.apache.kafka.trogdor.common.Platform)4 JsonRestServer (org.apache.kafka.trogdor.rest.JsonRestServer)4 File (java.io.File)3 Arrays (java.util.Arrays)3 Level (ch.qos.logback.classic.Level)2