Search in sources :

Example 1 with BooleanArgumentType

use of net.sourceforge.argparse4j.impl.type.BooleanArgumentType 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

StoreConstArgumentAction (net.sourceforge.argparse4j.impl.action.StoreConstArgumentAction)1 StoreTrueArgumentAction (net.sourceforge.argparse4j.impl.action.StoreTrueArgumentAction)1 CollectionArgumentChoice (net.sourceforge.argparse4j.impl.choice.CollectionArgumentChoice)1 BooleanArgumentType (net.sourceforge.argparse4j.impl.type.BooleanArgumentType)1 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)1 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)1 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)1