Search in sources :

Example 1 with AlreadySelectedException

use of org.apache.commons.cli.AlreadySelectedException in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerMain method run.

/*****************************************************************************
   * {@link Runnable} Interface
   ****************************************************************************/
public void run(String[] args) throws IOException {
    if (needsHelp(args)) {
        printHelp();
        System.exit(0);
    }
    try {
        CommandLine cli = _parser.parse(_options, args, true);
        runApplication(cli, args);
    } catch (MissingOptionException ex) {
        System.err.println("Missing argument: " + ex.getMessage());
        printHelp();
        System.exit(-2);
    } catch (MissingArgumentException ex) {
        System.err.println("Missing argument: " + ex.getMessage());
        printHelp();
        System.exit(-2);
    } catch (UnrecognizedOptionException ex) {
        System.err.println("Unknown argument: " + ex.getMessage());
        printHelp();
        System.exit(-2);
    } catch (AlreadySelectedException ex) {
        System.err.println("Argument already selected: " + ex.getMessage());
        printHelp();
        System.exit(-2);
    } catch (ParseException ex) {
        System.err.println(ex.getMessage());
        printHelp();
        System.exit(-2);
    } catch (TransformSpecificationException ex) {
        System.err.println("error with transform line: " + ex.getLine());
        System.err.println(ex.getMessage());
        System.exit(-1);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.commons.cli.ParseException) MissingOptionException(org.apache.commons.cli.MissingOptionException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.commons.cli.ParseException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 2 with AlreadySelectedException

use of org.apache.commons.cli.AlreadySelectedException in project incubator-systemml by apache.

the class DMLScript method executeScript.

/**
	 * Single entry point for all public invocation alternatives (e.g.,
	 * main, executeScript, JaqlUdf etc)
	 * 
	 * @param conf Hadoop configuration
	 * @param args arguments
	 * @return true if success, false otherwise
	 * @throws DMLException if DMLException occurs
	 * @throws ParseException if ParseException occurs
	 */
public static boolean executeScript(Configuration conf, String[] args) throws DMLException {
    //parse arguments and set execution properties
    //keep old rtplatform
    RUNTIME_PLATFORM oldrtplatform = rtplatform;
    //keep old explain
    ExplainType oldexplain = EXPLAIN;
    Options options = createCLIOptions();
    try {
        DMLOptions dmlOptions = parseCLArguments(args, options);
        // String[] scriptArgs = null; //optional script arguments
        // boolean namedScriptArgs = false;
        STATISTICS = dmlOptions.stats;
        STATISTICS_COUNT = dmlOptions.statsCount;
        USE_ACCELERATOR = dmlOptions.gpu;
        FORCE_ACCELERATOR = dmlOptions.forceGPU;
        EXPLAIN = dmlOptions.explainType;
        ENABLE_DEBUG_MODE = dmlOptions.debug;
        SCRIPT_TYPE = dmlOptions.scriptType;
        rtplatform = dmlOptions.execMode;
        String fnameOptConfig = dmlOptions.configFile;
        boolean isFile = dmlOptions.filePath != null;
        String fileOrScript = isFile ? dmlOptions.filePath : dmlOptions.script;
        boolean help = dmlOptions.help;
        if (help) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("systemml", options);
            return true;
        }
        if (dmlOptions.clean) {
            cleanSystemMLWorkspace();
            return true;
        }
        //set log level
        if (!ENABLE_DEBUG_MODE)
            setLoggingProperties(conf);
        //Step 2: prepare script invocation
        if (isFile && StringUtils.endsWithIgnoreCase(fileOrScript, ".pydml")) {
            SCRIPT_TYPE = ScriptType.PYDML;
        }
        String dmlScriptStr = readDMLScript(isFile, fileOrScript);
        Map<String, String> argVals = dmlOptions.argVals;
        DML_FILE_PATH_ANTLR_PARSER = dmlOptions.filePath;
        //Step 3: invoke dml script
        printInvocationInfo(fileOrScript, fnameOptConfig, argVals);
        if (ENABLE_DEBUG_MODE) {
            // inner try loop is just to isolate the debug exception, which will allow to manage the bugs from debugger v/s runtime
            launchDebugger(dmlScriptStr, fnameOptConfig, argVals, SCRIPT_TYPE);
        } else {
            execute(dmlScriptStr, fnameOptConfig, argVals, args, SCRIPT_TYPE);
        }
    } catch (AlreadySelectedException e) {
        System.err.println("Mutually exclusive options were selected. " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("systemml", options);
        return false;
    } catch (org.apache.commons.cli.ParseException e) {
        System.err.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("systemml", options);
    } catch (ParseException pe) {
        throw pe;
    } catch (DMLScriptException e) {
        //rethrow DMLScriptException to propagate stop call
        throw e;
    } catch (Exception ex) {
        LOG.error("Failed to execute DML script.", ex);
        throw new DMLException(ex);
    } finally {
        //reset runtime platform and visualize flag
        rtplatform = oldrtplatform;
        EXPLAIN = oldexplain;
    }
    return true;
}
Also used : Options(org.apache.commons.cli.Options) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) HopsException(org.apache.sysml.hops.HopsException) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) LopsException(org.apache.sysml.lops.LopsException) LanguageException(org.apache.sysml.parser.LanguageException) IOException(java.io.IOException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.sysml.parser.ParseException) DMLDebuggerException(org.apache.sysml.debug.DMLDebuggerException) HelpFormatter(org.apache.commons.cli.HelpFormatter) ExplainType(org.apache.sysml.utils.Explain.ExplainType) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) ParseException(org.apache.sysml.parser.ParseException)

Example 3 with AlreadySelectedException

use of org.apache.commons.cli.AlreadySelectedException in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsMergerMain method run.

/*****************************************************************************
   * {@link Runnable} Interface
   ****************************************************************************/
public void run(String[] args) throws IOException {
    if (needsHelp(args)) {
        printHelp();
        System.exit(0);
    }
    try {
        CommandLine cli = _parser.parse(_options, args, true);
        runApplication(cli, args);
    } catch (MissingOptionException ex) {
        System.err.println("Missing argument: " + ex.getMessage());
        printHelp();
    } catch (MissingArgumentException ex) {
        System.err.println("Missing argument: " + ex.getMessage());
        printHelp();
    } catch (UnrecognizedOptionException ex) {
        System.err.println("Unknown argument: " + ex.getMessage());
        printHelp();
    } catch (AlreadySelectedException ex) {
        System.err.println("Argument already selected: " + ex.getMessage());
        printHelp();
    } catch (ParseException ex) {
        System.err.println(ex.getMessage());
        printHelp();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.commons.cli.ParseException) MissingOptionException(org.apache.commons.cli.MissingOptionException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.commons.cli.ParseException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Aggregations

IOException (java.io.IOException)3 AlreadySelectedException (org.apache.commons.cli.AlreadySelectedException)3 CommandLine (org.apache.commons.cli.CommandLine)2 MissingArgumentException (org.apache.commons.cli.MissingArgumentException)2 MissingOptionException (org.apache.commons.cli.MissingOptionException)2 ParseException (org.apache.commons.cli.ParseException)2 UnrecognizedOptionException (org.apache.commons.cli.UnrecognizedOptionException)2 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Options (org.apache.commons.cli.Options)1 DMLDebuggerException (org.apache.sysml.debug.DMLDebuggerException)1 HopsException (org.apache.sysml.hops.HopsException)1 LopsException (org.apache.sysml.lops.LopsException)1 LanguageException (org.apache.sysml.parser.LanguageException)1 ParseException (org.apache.sysml.parser.ParseException)1 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1 DMLScriptException (org.apache.sysml.runtime.DMLScriptException)1 ExplainType (org.apache.sysml.utils.Explain.ExplainType)1