Search in sources :

Example 1 with StoreTrueArgumentAction

use of net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction in project atomix by atomix.

the class AtomixAgent method createParser.

/**
 * Creates an agent argument parser.
 */
private static ArgumentParser createParser() {
    // Argument type for node ID/location formatted id@host:port.
    final ArgumentType<NodeConfig> nodeArgumentType = (ArgumentParser argumentParser, Argument argument, String value) -> new NodeConfig().setId(parseMemberId(value)).setAddress(parseAddress(value));
    // Argument type for node addresses formatted host:port.
    final ArgumentType<Address> addressArgumentType = (argumentParser, argument, value) -> Address.from(value);
    // A list of all available logback log levels.
    final List<String> logLevels = Arrays.asList(Level.ALL.toString(), Level.OFF.toString(), Level.ERROR.toString(), Level.WARN.toString(), Level.INFO.toString(), Level.DEBUG.toString(), Level.TRACE.toString());
    final ArgumentParser parser = ArgumentParsers.newArgumentParser("AtomixServer").defaultHelp(true).description("Runs the Atomix agent with the given arguments. Arbitrary configuration options may be overridden " + "by specifying the option path and value as an optional argument, e.g. --cluster.node.id node-1");
    parser.addArgument("--member", "-m").type(String.class).nargs("?").required(false).help("The local member identifier, used in intra-cluster communication.");
    parser.addArgument("--address", "-a").type(addressArgumentType).metavar("HOST:PORT").nargs("?").required(false).help("The address for the local member. If no address is specified, the first public interface will be used.");
    parser.addArgument("--host").type(String.class).nargs("?").required(false).help("The host on which this member runs, used for host-aware partition management.");
    parser.addArgument("--rack").type(String.class).nargs("?").required(false).help("The rack on which this member runs, used for rack-aware partition management.");
    parser.addArgument("--zone").type(String.class).nargs("?").required(false).help("The zone in which this member runs, used for zone-aware partition management.");
    parser.addArgument("--config", "-c").metavar("CONF|JSON|PROPERTIES").type(File.class).nargs("*").required(false).setDefault(System.getProperty("atomix.config.files") != null ? Lists.newArrayList(System.getProperty("atomix.config.files").split(",")) : Lists.newArrayList()).help("The Atomix configuration. Can be specified as a file path or JSON/YAML string.");
    parser.addArgument("--ignore-resources").action(new StoreTrueArgumentAction()).setDefault(false).help("Ignores classpath resources when loading configuration files. Only valid when configuration file(s) are provided.");
    parser.addArgument("--log-config").metavar("FILE").type(String.class).nargs("?").setDefault(System.getProperty("atomix.logback")).help("The path to an optional logback configuration file outside the classpath.");
    parser.addArgument("--log-dir").metavar("FILE").type(String.class).nargs("?").setDefault(System.getProperty("atomix.log.directory", new File(System.getProperty("user.dir"), "logs").getPath())).help("The path to the Atomix log directory. " + "This option is only valid for logback configurations that employ the atomix.log.directory property.");
    parser.addArgument("--log-level").metavar("LEVEL").type(String.class).choices(logLevels).nargs("?").setDefault(System.getProperty("atomix.log.level", Level.DEBUG.toString())).help("The globally filtered log level for all Atomix logs. " + "This option is only valid for logback configurations that employ the atomix.log.level property.");
    parser.addArgument("--file-log-level").metavar("LEVEL").type(String.class).choices(logLevels).nargs("?").setDefault(System.getProperty("atomix.log.file.level", Level.DEBUG.toString())).help("The file log level. This option is only valid for logback configurations that employ the " + "atomix.log.file.level property.");
    parser.addArgument("--console-log-level").metavar("LEVEL").type(String.class).choices(logLevels).nargs("?").setDefault(System.getProperty("atomix.log.console.level", Level.INFO.toString())).help("The console log level. This option is only valid for logback configurations that employ the " + "atomix.log.console.level property.");
    parser.addArgument("--data-dir").metavar("FILE").type(String.class).nargs("?").setDefault(System.getProperty("atomix.data", ".data")).help("The default Atomix data directory. Defaults to .data");
    parser.addArgument("--bootstrap", "-b").nargs("*").type(nodeArgumentType).metavar("NAME@HOST:PORT").required(false).help("The set of static members to join. When provided, bootstrap node discovery will be used.");
    parser.addArgument("--multicast").action(new StoreTrueArgumentAction()).setDefault(false).help("Enables multicast discovery. Note that the network must support multicast for this feature to work.");
    parser.addArgument("--multicast-group").type(String.class).metavar("IP").help("Sets the multicast group. Defaults to 230.0.0.1");
    parser.addArgument("--multicast-port").type(Integer.class).metavar("PORT").help("Sets the multicast port. Defaults to 54321");
    parser.addArgument("--http-host").type(String.class).metavar("HOST").required(false).setDefault("0.0.0.0").help("Sets the host to which to bind the HTTP server. Defaults to 0.0.0.0 (all interfaces)");
    parser.addArgument("--http-port", "-p").type(Integer.class).metavar("PORT").required(false).setDefault(5678).help("Sets the port on which to run the HTTP server. Defaults to 5678");
    return parser;
}
Also used : Arrays(java.util.Arrays) Address(io.atomix.utils.net.Address) ManagedRestService(io.atomix.rest.ManagedRestService) StoreTrueArgumentAction(net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Atomix(io.atomix.core.Atomix) Lists(com.google.common.collect.Lists) AtomixConfig(io.atomix.core.AtomixConfig) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) NodeConfig(io.atomix.cluster.NodeConfig) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentType(net.sourceforge.argparse4j.inf.ArgumentType) Namespace(net.sourceforge.argparse4j.inf.Namespace) Map(java.util.Map) MulticastDiscoveryConfig(io.atomix.cluster.discovery.MulticastDiscoveryConfig) MemberId(io.atomix.cluster.MemberId) Argument(net.sourceforge.argparse4j.inf.Argument) MalformedAddressException(io.atomix.utils.net.MalformedAddressException) RestService(io.atomix.rest.RestService) BootstrapDiscoveryConfig(io.atomix.cluster.discovery.BootstrapDiscoveryConfig) Logger(org.slf4j.Logger) ArgumentParsers(net.sourceforge.argparse4j.ArgumentParsers) File(java.io.File) Level(ch.qos.logback.classic.Level) List(java.util.List) Argument(net.sourceforge.argparse4j.inf.Argument) Address(io.atomix.utils.net.Address) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) File(java.io.File) NodeConfig(io.atomix.cluster.NodeConfig) StoreTrueArgumentAction(net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction)

Example 2 with StoreTrueArgumentAction

use of net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction in project neo4j by neo4j.

the class CliArgHelper method setupParser.

private static ArgumentParser setupParser(ParameterMap parameterMap) {
    ArgumentParser parser = ArgumentParsers.newFor("cypher-shell").build().defaultHelp(true).description(format("A command line shell where you can execute Cypher against an instance of Neo4j. " + "By default the shell is interactive but you can use it for scripting by passing cypher " + "directly on the command line or by piping a file with cypher statements (requires Powershell on Windows)." + "%n%n" + "example of piping a file:%n" + "  cat some-cypher.txt | cypher-shell"));
    ArgumentGroup connGroup = parser.addArgumentGroup("connection arguments");
    connGroup.addArgument("-a", "--address").help("address and port to connect to").setDefault(String.format("%s://%s:%d", CliArgs.DEFAULT_SCHEME, CliArgs.DEFAULT_HOST, CliArgs.DEFAULT_PORT));
    connGroup.addArgument("-u", "--username").setDefault("").help("username to connect as. Can also be specified using environment variable " + ConnectionConfig.USERNAME_ENV_VAR);
    connGroup.addArgument("-p", "--password").setDefault("").help("password to connect with. Can also be specified using environment variable " + ConnectionConfig.PASSWORD_ENV_VAR);
    connGroup.addArgument("--encryption").help("whether the connection to Neo4j should be encrypted. This must be consistent with Neo4j's " + "configuration. If choosing '" + Encryption.DEFAULT.name().toLowerCase() + "' the encryption setting is deduced from the specified address. " + "For example the 'neo4j+ssc' protocol would use encryption.").choices(new CollectionArgumentChoice<>(Encryption.TRUE.name().toLowerCase(), Encryption.FALSE.name().toLowerCase(), Encryption.DEFAULT.name().toLowerCase())).setDefault(Encryption.DEFAULT.name().toLowerCase());
    connGroup.addArgument("-d", "--database").help("database to connect to. Can also be specified using environment variable " + ConnectionConfig.DATABASE_ENV_VAR).setDefault("");
    MutuallyExclusiveGroup failGroup = parser.addMutuallyExclusiveGroup();
    failGroup.addArgument("--fail-fast").help("exit and report failure on first error when reading from file (this is the default behavior)").dest("fail-behavior").setConst(FAIL_FAST).action(new StoreConstArgumentAction());
    failGroup.addArgument("--fail-at-end").help("exit and report failures at end of input when reading from file").dest("fail-behavior").setConst(FAIL_AT_END).action(new StoreConstArgumentAction());
    parser.setDefault("fail-behavior", FAIL_FAST);
    parser.addArgument("--format").help("desired output format, verbose displays results in tabular format and prints statistics, " + "plain displays data with minimal formatting").choices(new CollectionArgumentChoice<>(Format.AUTO.name().toLowerCase(), Format.VERBOSE.name().toLowerCase(), Format.PLAIN.name().toLowerCase())).setDefault(Format.AUTO.name().toLowerCase());
    parser.addArgument("-P", "--param").help("Add a parameter to this session. Example: `-P \"number => 3\"`. This argument can be specified multiple times.").action(new AddParamArgumentAction(parameterMap));
    parser.addArgument("--debug").help("print additional debug information").action(new StoreTrueArgumentAction());
    parser.addArgument("--non-interactive").help("force non-interactive mode, only useful if auto-detection fails (like on Windows)").dest("force-non-interactive").action(new StoreTrueArgumentAction());
    parser.addArgument("--sample-rows").help("number of rows sampled to compute table widths (only for format=VERBOSE)").type(new PositiveIntegerType()).dest("sample-rows").setDefault(CliArgs.DEFAULT_NUM_SAMPLE_ROWS);
    parser.addArgument("--wrap").help("wrap table column values if column is too narrow (only for format=VERBOSE)").type(new BooleanArgumentType()).setDefault(true);
    parser.addArgument("-v", "--version").help("print version of cypher-shell and exit").action(new StoreTrueArgumentAction());
    parser.addArgument("--driver-version").help("print version of the Neo4j Driver used and exit").dest("driver-version").action(new StoreTrueArgumentAction());
    parser.addArgument("cypher").nargs("?").help("an optional string of cypher to execute and then exit");
    parser.addArgument("-f", "--file").help("Pass a file with cypher statements to be executed. After the statements have been executed cypher-shell will be shutdown");
    return parser;
}
Also used : CollectionArgumentChoice(net.sourceforge.argparse4j.impl.choice.CollectionArgumentChoice) MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) StoreConstArgumentAction(net.sourceforge.argparse4j.impl.action.StoreConstArgumentAction) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) ArgumentGroup(net.sourceforge.argparse4j.inf.ArgumentGroup) BooleanArgumentType(net.sourceforge.argparse4j.impl.type.BooleanArgumentType) StoreTrueArgumentAction(net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction)

Aggregations

StoreTrueArgumentAction (net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction)2 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)2 Level (ch.qos.logback.classic.Level)1 Lists (com.google.common.collect.Lists)1 MemberId (io.atomix.cluster.MemberId)1 NodeConfig (io.atomix.cluster.NodeConfig)1 BootstrapDiscoveryConfig (io.atomix.cluster.discovery.BootstrapDiscoveryConfig)1 MulticastDiscoveryConfig (io.atomix.cluster.discovery.MulticastDiscoveryConfig)1 Atomix (io.atomix.core.Atomix)1 AtomixConfig (io.atomix.core.AtomixConfig)1 ManagedRestService (io.atomix.rest.ManagedRestService)1 RestService (io.atomix.rest.RestService)1 Address (io.atomix.utils.net.Address)1 MalformedAddressException (io.atomix.utils.net.MalformedAddressException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1