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();
}
}
}
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;
}
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 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);
}
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")));
}
Aggregations