Example usage for org.apache.commons.cli Option getOpt

List of usage examples for org.apache.commons.cli Option getOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getOpt.

Prototype

public String getOpt() 

Source Link

Document

Retrieve the name of this Option.

Usage

From source file:org.openanzo.client.cli.RdfIOCommand.java

RdfInputArgument getRdfInputOption(CommandContext context, CommandLine cl, Option option,
        RDFFormat formatOverride, String charsetName) throws AnzoException {
    String fileOption = cl.getOptionValue(option.getOpt());
    if (fileOption == null)
        return null;
    return getArgumentAsInputStream(context, fileOption, formatOverride, charsetName);
}

From source file:org.openanzo.client.cli.RdfIOCommand.java

Pair<File, RDFFormat> getFileOption(CommandLine cl, Option option, RDFFormat formatOverride, boolean exists)
        throws AnzoException {
    String fileOption = cl.getOptionValue(option.getOpt());
    File file = null;/*ww w  .  ja  v  a 2 s .c o m*/
    RDFFormat format = null;
    if (fileOption != null) {
        file = new File(fileOption);
        if (exists && !file.isFile()) {
            throw new InvalidArgumentException("File not found:" + file);
        }
        format = formatOverride != null ? formatOverride : RDFFormat.forFileName(file.getName());
    }

    return file == null ? null : new Pair<File, RDFFormat>(file, format);
}

From source file:org.openanzo.client.cli.RdfIOCommand.java

URI getURIOption(CommandLine cl, Option option, CommandContext context) throws AnzoException {
    URI uri = null;/*from w  w w  . j  a  va 2s. co  m*/
    if (cl.hasOption(option.getOpt())) {
        String uriString = cl.getOptionValue(option.getOpt());
        try {
            uri = context.getURI(uriString);
        } catch (URISyntaxException e) {
            throw new InvalidArgumentException("illegal URI: " + uriString);
        }
    }
    return uri;
}

From source file:org.openanzo.client.cli.RdfIOCommand.java

boolean isFlagSet(CommandLine cl, Option option) {
    return cl.hasOption(option.getOpt());
}

From source file:org.openbel.framework.tools.CacheManager.java

/**
 * Handle the cli option that was provided.
 *
 * @param option {@link Option} the current option to handle
 *///from  www  .java2s  .  c o m
private void handleOption(Option option) {
    if (LIST_CACHE_OPTION.equals(option.getOpt())) {
        handleListCache();
    } else if (CACHE_RESOURCE_OPTION.equals(option.getOpt())) {
        handleLoadResource(option);
    } else if (CACHE_SYSCONFIG_FILE_OPTION.equals(option.getOpt())) {
        handleLoadDefaultIndex();
    } else if (CACHE_INDEX_FILE.equals(option.getOpt())) {
        handleLoadIndex(option.getValue());
    } else if (PURGE_CACHE_OPTION.equals(option.getOpt())) {
        handlePurgeCache();
    } else if (GENERATE_CHECKSUM_OPTION.equals(option.getOpt())) {
        handleGenerateHash(option);
    }
}

From source file:org.openmeetings.cli.OmHelpFormatter.java

private StringBuilder getReqOptionsString(Options opts) {
    String delim = "";
    StringBuilder result = new StringBuilder();
    for (Option o : getReqOptions(opts)) {
        result.append(delim).append("-").append(o.getOpt());
        delim = "|";
    }//www  .  ja v a2  s  . com
    return result;
}

From source file:org.openrdf.console.Console.java

public static void main(final String[] args) throws IOException {
    final Console console = new Console();
    final Option helpOption = new Option("h", "help", false, "print this help");
    final Option versionOption = new Option("v", "version", false, "print version information");
    final Option serverURLOption = new Option("s", "serverURL", true,
            "URL of Sesame server to connect to, e.g. http://localhost/openrdf-sesame/");
    final Option dirOption = new Option("d", "dataDir", true, "Sesame data dir to 'connect' to");
    Option echoOption = new Option("e", "echo", false,
            "echoes input back to stdout, useful for logging script sessions");
    Option quietOption = new Option("q", "quiet", false, "suppresses prompts, useful for scripting");
    Option forceOption = new Option("f", "force", false,
            "always answer yes to (suppressed) confirmation prompts");
    Option cautiousOption = new Option("c", "cautious", false,
            "always answer no to (suppressed) confirmation prompts");
    Option exitOnErrorMode = new Option("x", "exitOnError", false,
            "immediately exit the console on the first error");
    final Options options = new Options();
    OptionGroup cautionGroup = new OptionGroup().addOption(cautiousOption).addOption(forceOption)
            .addOption(exitOnErrorMode);
    OptionGroup locationGroup = new OptionGroup().addOption(serverURLOption).addOption(dirOption);
    options.addOptionGroup(locationGroup).addOptionGroup(cautionGroup);
    options.addOption(helpOption).addOption(versionOption).addOption(echoOption).addOption(quietOption);
    CommandLine commandLine = parseCommandLine(args, console, options);
    handleInfoOptions(console, helpOption, versionOption, options, commandLine);
    console.consoleIO.setEcho(commandLine.hasOption(echoOption.getOpt()));
    console.consoleIO.setQuiet(commandLine.hasOption(quietOption.getOpt()));
    exitOnError = commandLine.hasOption(exitOnErrorMode.getOpt());
    String location = handleOptionGroups(console, serverURLOption, dirOption, forceOption, cautiousOption,
            options, cautionGroup, locationGroup, commandLine);
    final String[] otherArgs = commandLine.getArgs();
    if (otherArgs.length > 1) {
        printUsage(console.consoleIO, options);
        System.exit(1);//  ww w  .  j  a v a 2s  .co m
    }
    connectAndOpen(console, locationGroup.getSelected(), location, otherArgs);
    console.start();
}

From source file:org.opentestsystem.airose.optionCli.ArgOptions.java

private String optionToString(Option o) {
    return "-" + o.getOpt() + ", --" + o.getLongOpt();
}

From source file:org.os.interpreter.RunnerStartupInfo.java

public boolean isValidOptions(boolean printHelpWhenInvalid) {

    try {//from  ww  w. ja v a  2  s.  c  o  m
        initOptions();

        for (Option opt : options.getOptions()) {
            if (opt.isRequired() && !commandLine.hasOption(opt.getOpt())) {

                if (printHelpWhenInvalid) {
                    showHelp();
                }

                return false;
            }
        }
        return true;
    } catch (ParseException e) {
        showHelp();

        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.overture.alloy.Main.java

/**
 * @param args//from   w  w w.  java  2 s. co  m
 * @throws Exception
 */
public static int execute(String[] args) throws Exception {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options options = new Options();
    Option helpOpt = new Option("?", "help", false, "print this message");

    Option vdmOpt = new Option("vdm", true, "the vdm input file to translate");
    vdmOpt.setRequired(true);
    Option outputOpt = new Option("o", "output", true, "a file path used to write the translated result to");
    Option suppressAlloyCheckOpt = new Option("nocheck", "noalloycheck", false,
            "run alloy to on the generated file");
    Option verboseOpt = new Option("v", "verbose", false, "verbose output when generating");
    Option extraAlloyTest = new Option("test2", "alloytest2", true,
            "exstra model used when checking the output");

    options.addOption(helpOpt);
    options.addOption(vdmOpt);
    options.addOption(outputOpt);
    options.addOption(suppressAlloyCheckOpt);
    options.addOption(verboseOpt);
    options.addOption(extraAlloyTest);

    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);

        if (line.hasOption(helpOpt.getOpt())) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("vdm2alloy", options);
            return 0;
        }

    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("vdm2alloy", options);
        return 1;
    }

    File input = null;
    File output = null;

    if (line.hasOption(vdmOpt.getOpt())) {
        input = new File(line.getOptionValue(vdmOpt.getOpt()));
    }

    if (line.hasOption(outputOpt.getOpt())) {
        String fileName = line.getOptionValue(outputOpt.getOpt());
        if (!fileName.endsWith(".als")) {
            fileName += ".als";
        }
        output = new File(fileName);
    }

    boolean verbose = line.hasOption(verboseOpt.getOpt());

    Settings.dialect = Dialect.VDM_SL;
    TypeCheckResult<List<AModuleModules>> result = TypeCheckerUtil.typeCheckSl(input);

    if (result.errors.isEmpty()) {
        File tmpFile = null;
        if (output == null) {
            tmpFile = File.createTempFile("vdm2alloy", ".als");
        } else {
            tmpFile = output;
        }

        Alloy2VdmAnalysis analysis = new Alloy2VdmAnalysis(
                tmpFile.getName().substring(0, tmpFile.getName().indexOf(".")));
        result.result.get(0).apply(analysis, new Context());

        // Alloy2VdmAnalysis analysis = new Alloy2VdmAnalysis(tmpFile.getName().substring(0,
        // tmpFile.getName().indexOf(".")));
        // result.result.get(0).apply(analysis);

        analysis.components.add(new Pred("show", "", ""));
        analysis.components.add(new Run("show"));

        FileWriter outFile = new FileWriter(tmpFile);
        PrintWriter out = new PrintWriter(outFile);
        for (Part string : analysis.components) {
            if (verbose) {
                System.out.println(string);
            }
            out.println(string);
        }

        out.close();

        if (!line.hasOption(suppressAlloyCheckOpt.getOpt())) {
            System.out.println("\n------------------------------------");
            System.out.println("Running Alloy...\n");
            System.out.println("Temp file: " + tmpFile.getAbsolutePath());

            System.out.println("Running Alloy on file: " + tmpFile.getName());
            int exitCode = Terminal
                    .execute(new String[] { "-alloy", tmpFile.getAbsolutePath(), "-a", "-s", "SAT4J" });
            if (exitCode != 0) {
                return exitCode;
            }

            if (line.hasOption(extraAlloyTest.getOpt())) {
                String testInputPath = line.getOptionValue(extraAlloyTest.getOpt());
                System.out.println("Running Alloy on file: " + testInputPath);
                Terminal.main(new String[] { "-alloy", testInputPath, "-a", "-s", "SAT4J" });
            }
        }
    } else {
        System.err.println("Errors in input VDM model");
        return 1;
    }
    return 0;
}