Search in sources :

Example 61 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser 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)

Example 62 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project claw-compiler by C2SM-RCM.

the class CLIOptions method parseArguments.

public static CLIOptions parseArguments(String[] args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newFor("claw-cx2t").build().description("The CLAW Compiler is a " + "source-to-source translator working on the XcodeML intermediate representation");
    Namespace parsedArgs = null;
    try {
        parser.addArgument("input-xast-file").nargs("?").help("Input XCodeML file");
        MutuallyExclusiveGroup qOpts = parser.addMutuallyExclusiveGroup("Query options");
        qOpts.addArgument("--print-opts").action(Arguments.storeTrue()).help("Print processed cmdline options");
        qOpts.addArgument("--version").action(Arguments.storeTrue()).help("Print version");
        qOpts.addArgument("-tl", "--target-list").action(Arguments.storeTrue()).help("List all targets supported by code transformation");
        qOpts.addArgument("-dl", "--directive-list").action(Arguments.storeTrue()).help("List all directive languages supported by code generation");
        qOpts.addArgument("-sc", "--show-config").action(Arguments.storeTrue()).help("Display the current configuration");
        ArgumentGroup cOpts = parser.addArgumentGroup("Translator options");
        cOpts.addArgument("-l", "--suppress-pp-line-directives").action(Arguments.storeTrue()).help("Suppress line directive in decompiled code");
        cOpts.addArgument("-cp", "--config-path").help("Path to configuration directory");
        cOpts.addArgument("-c", "--config").help("Path to translator configuration file");
        cOpts.addArgument("-t", "--target").help("Code transformation target platform");
        cOpts.addArgument("-dir", "--directive").help("Target directive language to be used in code generation");
        cOpts.addArgument("-d", "--debug").action(Arguments.storeTrue()).help("Enable output debug message");
        cOpts.addArgument("-f", "--out-ftn-file").help("Output file for decompiled FORTRAN source");
        cOpts.addArgument("-o", "--out-xast-file").help("Output file for transformed XcodeML");
        cOpts.addArgument("-r", "--report").help("Output file for the transformation report");
        cOpts.addArgument("-M", "--mod-include-dir").nargs("*").action(Arguments.append()).help("Search directory for .xmod files");
        cOpts.addArgument("-w", "--max-fortran-line-length").type(Integer.class).help("Number of character per line in decompiled code");
        cOpts.addArgument("-fp", "--force-pure").action(Arguments.storeTrue()).help("Exit the translator if a PURE subroutine/function has to be transformed");
        cOpts.addArgument("-m", "--model-config").help("Model configuration file for SCA transformation");
        cOpts.addArgument("-x", "--override-cfg-key").nargs("*").action(Arguments.append()).help("Override configuration option. Has higher priority than base and user configuration");
        cOpts.addArgument("-ap", "--add-paren").action(Arguments.storeTrue()).help("Force backend to add parentheses around binary mathematical operations");
        cOpts.addArgument("-td", "--trans-path-dir").nargs("*").action(Arguments.append()).help("Search directory for external transformation set");
        parsedArgs = parser.parseArgs(args);
    } catch (HelpScreenException hse) {
        return null;
    } catch (ArgumentParserException ape) {
        parser.handleError(ape);
        throw ape;
    }
    CLIOptions opts = new CLIOptions(parsedArgs);
    return opts;
}
Also used : HelpScreenException(net.sourceforge.argparse4j.helper.HelpScreenException) MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ArgumentGroup(net.sourceforge.argparse4j.inf.ArgumentGroup)

Example 63 with ArgumentParser

use of net.sourceforge.argparse4j.inf.ArgumentParser in project claw-compiler by C2SM-RCM.

the class Options method parseCmdlineArguments.

public static Options parseCmdlineArguments(String[] args, Path workingDir) throws Exception {
    ArgumentParser parser = ArgumentParsers.newFor("clawfc").build().description("The CLAW Compiler is a " + "source-to-source translator working on the XcodeML intermediate representation");
    Namespace parsedArgs = null;
    try {
        parser.addArgument("fortran-file").nargs("*").action(Arguments.append()).help("Input file");
        MutuallyExclusiveGroup qOpts = parser.addMutuallyExclusiveGroup("Query options");
        qOpts.addArgument("--list-targets", "--target-list").action(Arguments.storeTrue()).help("List available types of accelerator hardware");
        qOpts.addArgument("--list-directives", "--directive-list").action(Arguments.storeTrue()).help("List supported accelerator directive languages");
        qOpts.addArgument("--show-config").action(Arguments.storeTrue()).help("List the current configuration information. If used with --config, list the information" + " from the specific configuration");
        qOpts.addArgument("--version").action(Arguments.storeTrue()).help("Print version");
        qOpts.addArgument("--print-install-cfg", "--show-env").action(Arguments.storeTrue()).help("Print install configuration");
        qOpts.addArgument("--print-opts").action(Arguments.storeTrue()).help("Print processed cmdline options");
        qOpts.addArgument("--print-claw-files").action(Arguments.storeTrue()).help("Print input files which use CLAW directives");
        MutuallyExclusiveGroup outOpts = parser.addMutuallyExclusiveGroup("Compiler output options");
        outOpts.addArgument("-o", "--output-file").help("Output file for the transformed FORTRAN code. If not given, code is printed to stdout");
        outOpts.addArgument("-O", "--output-dir").help("Output directory for transformed FORTRAN files");
        ArgumentGroup cOpts = parser.addArgumentGroup("Compiler options");
        cOpts.addArgument("-I", "--pp-include-dir").nargs("*").action(Arguments.append()).help("Add the directory to the search path for include files reference in preprocessor directives and FORTRAN include statements");
        cOpts.addArgument("-PO", "--pp-output-dir").help("Output directory for preprocessed FORTRAN source files");
        cOpts.addArgument("-D", "--add-macro").nargs("*").action(Arguments.append()).help("Predefine macro");
        cOpts.addArgument("-SI", "--src-include-dir").nargs("*").action(Arguments.append()).help("Add directory to the search path for the source of referenced Fortran modules");
        cOpts.addArgument("-M", "-MI", "--mod-include-dir").nargs("*").action(Arguments.append()).help("Add directory to the search path for .xmod files.");
        cOpts.addArgument("-MO", "--mod-output-dir").help("Output directory for .xmod files.");
        cOpts.addArgument("-MD", "--make-dep-file").nargs("?").setConst("").help("Generate GNU Make dependency file. Default value is <output file>.d");
        cOpts.addArgument("-J").nargs("*").action(Arguments.append()).help("DEPRECATED Add directory to the search path for the source of referenced Fortran modules and .xmod files." + " First given is also output directory for generated .xmod files");
        cOpts.addArgument("-BI", "--buildinfo-include-dir").nargs("*").action(Arguments.append()).help("Include directory for BuildInfo files");
        cOpts.addArgument("-BO", "--buildinfo-output-dir").help("Output directory for BuildInfo files");
        cOpts.addArgument("-XO", "--xast-output-dir").help("Output directory for modules transformed into XCodeML-AST");
        cOpts.addArgument("-TXO", "--txast-output-dir").help("Output directory for translated XCodeML-AST program units");
        cOpts.addArgument("-TRO", "--trans-report-output-dir").help("Output directory for transformation reports");
        cOpts.addArgument("-TSO", "--tsrc-output-dir").help("Output directory for decompiled source program units");
        cOpts.addArgument("-t", "--target").help("Type of target accelerator hardware");
        cOpts.addArgument("-d", "--directive").help("Specify accelerator directive language to be used for code generation");
        cOpts.addArgument("--config").help("Specify a different configuration for the translator");
        cOpts.addArgument("-m", "--model-config").help("Specific model configuration for SCA");
        cOpts.addArgument("-c", "--keep-comment").action(Arguments.storeTrue()).help("Keep comments in the transformed file");
        cOpts.addArgument("-v", "--verbose").action(Arguments.storeTrue()).help("Print processing status");
        cOpts.addArgument("--no-dep").action(Arguments.storeTrue()).help("Don't generate .mod or .xmod file for dependencies");
        cOpts.addArgument("--no-module-cache").action(Arguments.storeTrue()).help("Deactivate module cache in the front-end");
        cOpts.addArgument("-f", "--force").action(Arguments.storeTrue()).help("Force the translation of modules without directives");
        cOpts.addArgument("--force-pure").action(Arguments.storeTrue()).help("Force compiler to exit when transformation applied to PURE subroutine/function");
        cOpts.addArgument("--add-paren").action(Arguments.storeTrue()).help("Add parenthesis to binary operation in generated code");
        cOpts.addArgument("--debug").action(Arguments.storeTrue()).help("Display transformation debug information");
        cOpts.addArgument("--int-dir").help("Path to intermediate files directory (all existing contents will be removed)");
        cOpts.addArgument("--keep-int-files").action(Arguments.storeTrue()).help("Keep intermediate files");
        cOpts.addArgument("--debug-ffront").action(Arguments.storeTrue()).help("Drive OMNI Fortran front-end in debug mode");
        cOpts.addArgument("--skip-pp").action(Arguments.storeTrue()).help("Do not apply preprocessing to input and include files");
        MutuallyExclusiveGroup sOpts = parser.addMutuallyExclusiveGroup("Compiler debug options");
        sOpts.addArgument("--stop-pp").action(Arguments.storeTrue()).help("Stop after preprocessing");
        sOpts.addArgument("--stop-depscan").action(Arguments.storeTrue()).help("Stop after dependencies scan");
        sOpts.addArgument("--stop-xmod-gen").action(Arguments.storeTrue()).help("Stop after Xmod generation");
        sOpts.addArgument("--stop-xast-gen").action(Arguments.storeTrue()).help("Stop after XML-AST generation");
        sOpts.addArgument("--stop-trans").action(Arguments.storeTrue()).help("Stop after translator");
        sOpts.addArgument("--stop-dec").action(Arguments.storeTrue()).help("Stop after decompilation");
        cOpts.addArgument("--gen-buildinfo-files").action(Arguments.storeTrue()).help("Generate build information files for input and then stop");
        cOpts.addArgument("--gen-mod-files").nargs("*").action(Arguments.append()).setConst("").help("Generate xmod files for input and then stop. List of target module names can be optionally supplied.");
        cOpts.addArgument("-x", "--override-cfg-key").nargs("*").action(Arguments.append()).help("Override a configuration key:value pair from the command line. Higher " + "priority over base configuration and user configuration");
        cOpts.addArgument("--dump-cx2t-args").action(Arguments.storeTrue()).help("Print arguments passed to CX2T");
        MutuallyExclusiveGroup mpOpts = parser.addMutuallyExclusiveGroup("Compiler multiprocessing options");
        mpOpts.addArgument("-mp", "--max-num-mp-jobs").type(Integer.class).help("Maximum number of multiprocessing jobs");
        mpOpts.addArgument("--disable-mp").action(Arguments.storeTrue()).help("Disable multiprocessing");
        cOpts.addArgument("-mj", "--sync-with-gmake").action(Arguments.storeTrue()).help("Synchronize number of threads with GNU Make job server");
        ArgumentGroup dcOpts = parser.addArgumentGroup("Decompiler options");
        dcOpts.addArgument("--max-fortran-line-length", "-w").type(Integer.class).setDefault(Integer.valueOf(80)).help("Set the number of columns for the output FORTRAN file (default: 80)");
        dcOpts.addArgument("-l", "--add-pp-line-directives").action(Arguments.storeTrue()).help("Add preprocessor line directives in the output FORTRAN file");
        cOpts.addArgument("-E", "--only-preprocess").action(Arguments.storeTrue()).help("Only apply preprocessor to input files");
        ArgumentGroup pOpts = parser.addArgumentGroup("Process options");
        pOpts.addArgument("--add-pp-opts", "--Wp").nargs("*").action(Arguments.append()).help("Add preprocessor option");
        pOpts.addArgument("--add-ffront-opts", "--Wf").nargs("*").action(Arguments.append()).help("Add frontend option");
        pOpts.addArgument("--add-trans-opts", "--Wx").nargs("*").action(Arguments.append()).help("Add Xcode translator option");
        ArgumentGroup fcOpts = parser.addArgumentGroup("Fortran compiler options");
        final List<String> FC_COMPILER_VENDORS = Arrays.stream(FortranCompilerVendor.values()).map(val -> val.toString().toLowerCase()).collect(Collectors.toList());
        fcOpts.addArgument("--fc-vendor").choices(FC_COMPILER_VENDORS).help("Fortran compiler type");
        fcOpts.addArgument("--fc-cmd").help("Fortran compiler cmd");
        cOpts.addArgument("-td", "--trans-path-dir").nargs("*").action(Arguments.append()).help("Search directory for external transformation set");
        parser.addArgument("--ffront-debug-dir").help("Output directory to collect OMNI failures for easier debugging");
        parsedArgs = parser.parseArgs(args);
    } catch (HelpScreenException hse) {
        return null;
    } catch (ArgumentParserException ape) {
        parser.handleError(ape);
        throw ape;
    }
    Options opts = new Options(parsedArgs, workingDir);
    return opts;
}
Also used : HelpScreenException(net.sourceforge.argparse4j.helper.HelpScreenException) Arrays(java.util.Arrays) ArgumentParsers(net.sourceforge.argparse4j.ArgumentParsers) Set(java.util.Set) MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) FortranCompilerVendor(clawfc.Configuration.FortranCompilerVendor) Paths(java.nio.file.Paths) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Arguments(net.sourceforge.argparse4j.impl.Arguments) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) Namespace(net.sourceforge.argparse4j.inf.Namespace) Utils.sprintf(clawfc.Utils.sprintf) ArgumentGroup(net.sourceforge.argparse4j.inf.ArgumentGroup) Path(java.nio.file.Path) Collections(java.util.Collections) HelpScreenException(net.sourceforge.argparse4j.helper.HelpScreenException) MutuallyExclusiveGroup(net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace) ArgumentGroup(net.sourceforge.argparse4j.inf.ArgumentGroup)

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