Search in sources :

Example 41 with ArgumentParserException

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

Example 42 with ArgumentParserException

use of net.sourceforge.argparse4j.inf.ArgumentParserException in project template-compiler by Squarespace.

the class TemplateC method execute.

protected void execute(String[] args) {
    String version = buildVersion();
    ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME).description("Compile template files").version(version);
    parser.addArgument("--dump-plugins").action(Arguments.storeTrue()).help("Dump the list of registered plugins");
    parser.addArgument("--version", "-v").action(Arguments.version()).help("Show the version and exit");
    parser.addArgument("--stats", "-s").action(Arguments.storeTrue()).help("Dump stats for the template");
    parser.addArgument("--tree", "-t").action(Arguments.storeTrue()).help("Dump the syntax tree for the template");
    parser.addArgument("--json", "-j").type(String.class).help("JSON tree");
    parser.addArgument("--partials", "-p").type(String.class).help("JSON partials");
    parser.addArgument("--locale", "-l").type(String.class).help("Language tag for a locale");
    parser.addArgument("--preprocess", "-P").action(Arguments.storeTrue()).help("Preprocess the template");
    parser.addArgument("template").type(String.class).nargs("?").help("Template source");
    int exitCode = 1;
    try {
        Namespace res = parser.parseArgs(args);
        if (res.getBoolean("dump_plugins")) {
            dumpPlugins();
            System.exit(0);
        }
        if (res.getString("template") == null) {
            parser.printUsage();
            System.err.println("error: too few arguments");
            System.exit(exitCode);
        }
        boolean preprocess = res.getBoolean("preprocess");
        if (res.getBoolean("stats")) {
            exitCode = stats(res.getString("template"), preprocess);
        } else if (res.getBoolean("tree")) {
            exitCode = tree(res.getString("template"), preprocess);
        } else {
            exitCode = compile(res.getString("template"), res.getString("json"), res.getString("partials"), res.getString("locale"), preprocess);
        }
    } catch (CodeException | IOException e) {
        System.err.println(e.getMessage());
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    } finally {
        System.exit(exitCode);
    }
}
Also used : CodeException(com.squarespace.template.CodeException) IOException(java.io.IOException) ArgumentParserException(net.sourceforge.argparse4j.inf.ArgumentParserException) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) Namespace(net.sourceforge.argparse4j.inf.Namespace)

Aggregations

ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)42 Namespace (net.sourceforge.argparse4j.inf.Namespace)34 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)30 Properties (java.util.Properties)13 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)6 MutuallyExclusiveGroup (net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup)6 ArgumentGroup (net.sourceforge.argparse4j.inf.ArgumentGroup)4 Platform (org.apache.kafka.trogdor.common.Platform)4 JsonRestServer (org.apache.kafka.trogdor.rest.JsonRestServer)4 AnnotatorService (edu.illinois.cs.cogcomp.annotation.AnnotatorService)3 File (java.io.File)3 Path (java.nio.file.Path)3 List (java.util.List)3 Random (java.util.Random)3 HelpScreenException (net.sourceforge.argparse4j.internal.HelpScreenException)3 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2