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

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

Introduction

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

Prototype

public void setOptionalArg(boolean optionalArg) 

Source Link

Document

Sets whether this Option can have an optional argument.

Usage

From source file:edu.ksu.cis.indus.staticanalyses.concurrency.DeadlockAnalysisCLI.java

/**
 * The entry point to this class./*from w  w w  .  j a  v a2s  .c om*/
 * 
 * @param args command line arguments.
 * @throws RuntimeException when escape information and side-effect information calculation fails.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final CommandLineParser _parser = new GnuParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            final String _cmdLineSyn = "java " + DeadlockAnalysisCLI.class.getName()
                    + " <options> <classnames>";
            (new HelpFormatter()).printHelp(_cmdLineSyn, _options);
            System.exit(1);
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final DeadlockAnalysisCLI _cli = new DeadlockAnalysisCLI();

        if (_cl.hasOption('p')) {
            _cli.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }
        _cli.setClassNames(_cl.getArgList());
        _cli.<ITokens>execute();
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        final String _cmdLineSyn = "java " + DeadlockAnalysisCLI.class.getName() + " <options> <classnames>";
        (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, "");
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.concurrency.escape.EscapeAndReadWriteCLI.java

/**
 * The entry point to this class./*  w  ww .  j a va2s  .  c o m*/
 * 
 * @param args command line arguments.
 * @throws RuntimeException when escape information and side-effect information calculation fails.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final CommandLineParser _parser = new GnuParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            final String _cmdLineSyn = "java " + EscapeAndReadWriteCLI.class.getName()
                    + " <options> <classnames>";
            (new HelpFormatter()).printHelp(_cmdLineSyn, _options);
            System.exit(1);
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final EscapeAndReadWriteCLI _cli = new EscapeAndReadWriteCLI();

        if (_cl.hasOption('p')) {
            _cli.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }
        _cli.setClassNames(_cl.getArgList());
        _cli.<ITokens>execute();
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        final String _cmdLineSyn = "java " + EscapeAndReadWriteCLI.class.getName() + " <options> <classnames>";
        (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, "");
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.xmlizer.JimpleXMLizerCLI.java

/**
 * The entry point to execute this xmlizer from command prompt.
 * /* w ww. j  ava 2  s . c o m*/
 * @param s is the command-line arguments.
 * @throws RuntimeException when jimple xmlization fails.
 * @pre s != null
 */
public static void main(final String[] s) {
    final Scene _scene = Scene.v();

    final Options _options = new Options();
    Option _o = new Option("d", "dump directory", true, "The directory in which to write the xml files.  "
            + "If unspecified, the xml output will be directed standard out.");
    _o.setArgs(1);
    _o.setArgName("path");
    _o.setOptionalArg(false);
    _options.addOption(_o);
    _o = new Option("h", "help", false, "Display message.");
    _options.addOption(_o);
    _o = new Option("p", "soot-classpath", true, "Prepend this to soot class path.");
    _o.setArgs(1);
    _o.setArgName("classpath");
    _o.setOptionalArg(false);
    _options.addOption(_o);

    final HelpFormatter _help = new HelpFormatter();

    try {
        final CommandLine _cl = (new BasicParser()).parse(_options, s);
        final String[] _args = _cl.getArgs();

        if (_cl.hasOption('h')) {
            final String _cmdLineSyn = "java " + JimpleXMLizerCLI.class.getName() + "<options> <class names>";
            _help.printHelp(_cmdLineSyn.length(), _cmdLineSyn, "", _options, "", true);
        } else {
            if (_args.length > 0) {
                if (_cl.hasOption('p')) {
                    _scene.setSootClassPath(
                            _cl.getOptionValue('p') + File.pathSeparator + _scene.getSootClassPath());
                }

                final NamedTag _tag = new NamedTag("JimpleXMLizer");

                for (int _i = 0; _i < _args.length; _i++) {
                    final SootClass _sc = _scene.loadClassAndSupport(_args[_i]);
                    _sc.addTag(_tag);
                }
                final IProcessingFilter _filter = new TagBasedProcessingFilter(_tag.getName());
                writeJimpleAsXML(new Environment(_scene), _cl.getOptionValue('d'), null,
                        new UniqueJimpleIDGenerator(), _filter);
            } else {
                System.out.println("No classes were specified.");
            }
        }
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.concurrency.independence.IndependenceDetectionCLI.java

/**
 * The entry point to the program via command line.
 * //  ww  w  . j a v a  2s .co m
 * @param args is the command line arguments.
 * @throws RuntimeException when CLI fails.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("o", "output", true,
            "Directory into which jimple files will be written into. [required]");
    _option.setArgs(1);
    _option.setArgName("ouput-directory");
    _option.setRequired(true);
    _options.addOption(_option);
    _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("useV2", false, "Use version 2 of the atomicity detection algorithm.");
    _options.addOption(_option);
    _option = new Option("scheme", false,
            "Scheme to indicate atomicity. Valid values are 'tag-stmt' and 'tag-region'.  By default, 'tag-stmt' "
                    + "scheme is used. ");
    _option.setArgs(1);
    _option.setArgName("scheme-name");
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final CommandLineParser _parser = new GnuParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            final String _cmdLineSyn = "java " + IndependenceDetectionCLI.class.getName()
                    + " <options> <classnames>";
            (new HelpFormatter()).printHelp(_cmdLineSyn, _options);
            System.exit(1);
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final IndependenceDetectionCLI _cli;

        if (_cl.hasOption("useV2")) {
            _cli = new IndependenceDetectionCLI(new IndependentStmtDetectorv2());
        } else {
            _cli = new IndependenceDetectionCLI(new IndependentStmtDetector());
        }

        if (_cl.hasOption('p')) {
            _cli.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _cli.setClassNames(_cl.getArgList());
        _cli.setOutputDir(_cl.getOptionValue('o'));
        _cli.<ITokens>execute(_cl);
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        final String _cmdLineSyn = "java " + IndependenceDetectionCLI.class.getName()
                + " <options> <classnames>";
        (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, "");
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.flow.instances.ofa.OFAXMLizerCLI.java

/**
 * The entry point to the program via command line.
 * //w  ww.j av  a2  s . c om
 * @param args is the command line arguments.
 * @throws RuntimeException when object flow analysis fails.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("c", "cumulative", false, "Consider all root methods in the same execution.");
    _options.addOption(_option);
    _option = new Option("o", "output", true, "Directory into which xml files will be written into.");
    _option.setArgs(1);
    _options.addOption(_option);
    _option = new Option("j", "jimple", false, "Dump xmlized jimple.");
    _options.addOption(_option);
    _option = new Option("h", "help", false, "Display message.");
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("t", "ofa-type", false, "Type of analysis : fioi, fsoi, fios, fsos, fioirt, fsoirt.");
    _option.setArgs(1);
    _option.setArgName("type");
    _option.setOptionalArg(false);
    _option.setRequired(true);
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final PosixParser _parser = new PosixParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            printUsage(_options);
            System.exit(1);
        }

        String _outputDir = _cl.getOptionValue('o');

        if (_outputDir == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Defaulting to current directory for output.");
            }
            _outputDir = ".";
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final OFAXMLizerCLI _cli = new OFAXMLizerCLI();
        _cli.xmlizer.setXmlOutputDir(_outputDir);
        _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator());
        _cli.setCumulative(_cl.hasOption('c'));
        _cli.setClassNames(_cl.getArgList());
        _cli.type = _cl.getOptionValue('t');

        if (_cl.hasOption('p')) {
            _cli.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _cli.initialize();

        _cli.<ITokens>execute(_cl.hasOption('j'));
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line. \n" + _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.callgraphs.CallGraphXMLizerCLI.java

/**
 * The entry point to the program via command line.
 * //from  w w w  .  j  a v a  2  s . co m
 * @param args is the command line arguments.
 * @throws RuntimeException when the analyses fail.
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("c", "cumulative", false,
            "Builds one call graph that includes all root methods.");
    _options.addOption(_option);
    _option = new Option("o", "output", true,
            "Directory into which xml files will be written into.  Defaults to current directory if omitted");
    _option.setArgs(1);
    _option.setArgName("output-dir");
    _options.addOption(_option);
    _option = new Option("j", "jimple", false, "Dump xmlized jimple.");
    _option.setArgName("dump-jimple");
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", true, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("t", "call-graph-type", true,
            "Call graph type.  This has to be one of {cha, rta, ofa-oi, " + "ofa-oirt, ofa-os}.");
    _option.setArgs(1);
    _option.setArgName("type");
    _option.setRequired(true);
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    final PosixParser _parser = new PosixParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption('h')) {
            printUsage(_options);
            System.exit(1);
        }

        String _outputDir = _cl.getOptionValue('o');

        if (_outputDir == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Defaulting to current directory for output.");
            }
            _outputDir = ".";
        }

        if (_cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }

        final CallGraphXMLizerCLI _cli = new CallGraphXMLizerCLI();

        _cli.xmlizer.setXmlOutputDir(_outputDir);
        _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator());
        _cli.setCumulative(_cl.hasOption('c'));
        _cli.setClassNames(_cl.getArgList());
        _cli.addToSootClassPath(_cl.getOptionValue('p'));

        if (_cl.hasOption('S')) {
            _cli.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _cli.initialize();

        _cli.execute(_cl.hasOption('j'), _cl.getOptionValue('t'));
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:edu.ksu.cis.indus.staticanalyses.dependency.DependencyXMLizerCLI.java

/**
 * This is the entry point via command-line.
 * //from w ww  .j  av a 2  s  .  c o  m
 * @param args is the command line arguments.
 * @throws RuntimeException when an Throwable exception beyond our control occurs.
 * @pre args != null
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("o", "output", true,
            "Directory into which xml files will be written into.  Defaults to current directory if omitted");
    _option.setArgs(1);
    _option.setArgName("output-directory");
    _options.addOption(_option);
    _option = new Option("j", "jimple", false, "Dump xmlized jimple.");
    _options.addOption(_option);

    final DivergenceDA _fidda = DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION);
    _fidda.setConsiderCallSites(true);

    final DivergenceDA _bidda = DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION);
    _bidda.setConsiderCallSites(true);

    final NonTerminationSensitiveEntryControlDA _ncda = new NonTerminationSensitiveEntryControlDA();
    final Object[][] _dasOptions = {
            { "ibdda1", "Identifier based data dependence (Soot)", new IdentifierBasedDataDA() },
            { "ibdda2", "Identifier based data dependence (Indus)", new IdentifierBasedDataDAv2() },
            { "ibdda3", "Identifier based data dependence (Indus Optimized)", new IdentifierBasedDataDAv3() },
            { "rbdda", "Reference based data dependence", new ReferenceBasedDataDA() },
            { "nscda", "Non-termination sensitive Entry control dependence", _ncda },
            { "nicda", "Non-termination insensitive Entry control dependence",
                    new NonTerminationInsensitiveEntryControlDA(), },
            { "xcda", "Exit control dependence", new ExitControlDA() },
            { "sda", "Synchronization dependence", new SynchronizationDA() },
            { "frda1", "Forward Ready dependence v1", ReadyDAv1.getForwardReadyDA() },
            { "brda1", "Backward Ready dependence v1", ReadyDAv1.getBackwardReadyDA() },
            { "frda2", "Forward Ready dependence v2", ReadyDAv2.getForwardReadyDA() },
            { "brda2", "Backward Ready dependence v2", ReadyDAv2.getBackwardReadyDA() },
            { "frda3", "Forward Ready dependence v3", ReadyDAv3.getForwardReadyDA() },
            { "brda3", "Backward Ready dependence v3", ReadyDAv3.getBackwardReadyDA() },
            { "ida1", "Interference dependence v1", new InterferenceDAv1() },
            { "ida2", "Interference dependence v2", new InterferenceDAv2() },
            { "ida3", "Interference dependence v3", new InterferenceDAv3() },
            { "fdda", "Forward Intraprocedural Divergence dependence",
                    DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION), },
            { "bdda", "Backward Intraprocedural Divergence dependence",
                    DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION), },
            { "fidda", "Forward Intra+Interprocedural Divergence dependence", _fidda },
            { "bidda", "Backward Intra+Interprocedural Divergence dependence", _bidda },
            { "fpidda", "Forward Interprocedural Divergence dependence",
                    InterProceduralDivergenceDA
                            .getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION), },
            { "bpidda", "Backward Interprocedural Divergence dependence", InterProceduralDivergenceDA
                    .getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION), }, };
    _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("aliasedusedefv1", false, "Use version 1 of aliased use-def info.");
    _options.addOption(_option);
    _option = new Option("safelockanalysis", false, "Use safe-lock-analysis for ready dependence.");
    _options.addOption(_option);
    _option = new Option("ofaforinterference", false, "Use OFA for interference dependence.");
    _options.addOption(_option);
    _option = new Option("ofaforready", false, "Use OFA for ready dependence.");
    _options.addOption(_option);
    _option = new Option("exceptionalexits", false, "Consider exceptional exits for control dependence.");
    _options.addOption(_option);
    _option = new Option("commonuncheckedexceptions", false, "Consider common unchecked exceptions.");
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    for (int _i = 0; _i < _dasOptions.length; _i++) {
        final String _shortOption = _dasOptions[_i][0].toString();
        final String _description = _dasOptions[_i][1].toString();
        _option = new Option(_shortOption, false, _description);
        _options.addOption(_option);
    }

    final CommandLineParser _parser = new GnuParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            printUsage(_options);
            System.exit(1);
        }

        final DependencyXMLizerCLI _xmlizerCLI = new DependencyXMLizerCLI();
        String _outputDir = _cl.getOptionValue('o');

        if (_outputDir == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Defaulting to current directory for output.");
            }
            _outputDir = ".";
        }

        _xmlizerCLI.xmlizer.setXmlOutputDir(_outputDir);

        if (_cl.hasOption('p')) {
            _xmlizerCLI.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _xmlizerCLI.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _xmlizerCLI.dumpJimple = _cl.hasOption('j');
        _xmlizerCLI.useAliasedUseDefv1 = _cl.hasOption("aliasedusedefv1");
        _xmlizerCLI.useSafeLockAnalysis = _cl.hasOption("safelockanalysis");
        _xmlizerCLI.exceptionalExits = _cl.hasOption("exceptionalexits");
        _xmlizerCLI.commonUncheckedException = _cl.hasOption("commonuncheckedexceptions");

        final List<String> _classNames = _cl.getArgList();

        if (_classNames.isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }
        _xmlizerCLI.setClassNames(_classNames);

        final int _exitControlDAIndex = 6;

        if (_cl.hasOption(_dasOptions[_exitControlDAIndex][0].toString())) {
            _xmlizerCLI.das.add(_ncda);

            for (final Iterator<DependenceSort> _i = _ncda.getIds().iterator(); _i.hasNext();) {
                final DependenceSort _id = _i.next();
                MapUtils.putIntoCollectionInMapUsingFactory(_xmlizerCLI.info, _id, _ncda,
                        SetUtils.getFactory());
            }
        }

        if (!parseForDependenceOptions(_dasOptions, _cl, _xmlizerCLI)) {
            throw new ParseException("Atleast one dependence analysis must be requested.");
        }

        _xmlizerCLI.<ITokens>execute();
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:com.vectorization.client.Application.java

private static Options createOptions() {
    Options options = new Options();
    options.addOption("D", "database", true, "Database to use.");
    options.addOption("h", "host", true, "Connect to host.");
    OptionBuilder.withLongOpt("help");
    OptionBuilder.withDescription("Print this message");
    Option help = OptionBuilder.create();
    options.addOption(help);// w  w w  .j av  a 2s .  com
    Option passwordOption = new Option("p", "password", true, "Password to use when connecting "
            + "to server.  If password is not " + "given it's asked from the tty.");
    passwordOption.setOptionalArg(true);
    options.addOption(passwordOption);
    options.addOption("P", "port", true, "Port number to use for connection");
    options.addOption("u", "user", true, "User for login if not current user.");
    options.addOption("V", "version", false, "Output version information and exit.");
    return options;
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java

private static void initializeOptions() {
    options = new Options();

    Option inputOption = new Option("i", "inputPaths", true, "inputPaths file");
    inputOption.setRequired(true);//from   ww w. j  av  a2  s  .co  m
    inputOption.setArgs(Option.UNLIMITED_VALUES);
    inputOption.setOptionalArg(false);
    inputOption.setValueSeparator(',');
    options.addOption(inputOption);

    options.addOption("f", "filename", true, "output filename");
    options.addOption("o", "output-dir", true, "output directory");
    options.addOption("m", "export-markup", false, "export html markup");
    options.addOption("n", "no-mobi", false, "no Mobi conversion, just markup, NOTE: makes -m implicit!");
    options.addOption("t", "title", true, "Document title");
    options.addOption("h", "help", false, "show this help");
    options.addOption("d", "debugMarkupOutput", false, "show debug output in html markup");
    options.addOption("u", "use-calibre", false, "use calibre ebook-convert instead of kindlegen");

    Option picturesOption = new Option("r", "replace latex formulas with pictures, override html");
    picturesOption.setLongOpt("replace-with-images");
    picturesOption.setArgs(0);
    picturesOption.setRequired(false);
    options.addOption(picturesOption);

    // implementation specific options
    options.addOption(
            ((LatexToHtmlConverter) applicationContext.getBean("latex2html-converter")).getExecOption());
    options.addOption(
            ((HtmlToMobiConverter) applicationContext.getBean(KINDLEGEN_HTML2MOBI_CONVERTER)).getExecOption());
    options.addOption(
            ((HtmlToMobiConverter) applicationContext.getBean(CALIBRE_HTML2MOBI_CONVERTER)).getExecOption());
}

From source file:de.zib.scalaris.Main.java

/**
 * Creates the options the command line should understand.
 * //from   w  ww. ja  va  2  s.co  m
 * @return the options the program understands
 */
private static Options getOptions() {
    Options options = new Options();
    OptionGroup group = new OptionGroup();

    /* Note: arguments are set to be optional since we implement argument
     * checks on our own (commons.cli is not flexible enough and only
     * checks for the existence of a first argument)
     */

    options.addOption(new Option("h", "help", false, "print this message"));

    options.addOption(new Option("v", "verbose", false, "print verbose information, e.g. the properties read"));

    Option read = new Option("r", "read", true, "read an item");
    read.setArgName("key");
    read.setArgs(1);
    read.setOptionalArg(true);
    group.addOption(read);

    Option write = new Option("w", "write", true, "write an item");
    write.setArgName("key> <value");
    write.setArgs(2);
    write.setOptionalArg(true);
    group.addOption(write);

    Option publish = new Option("p", "publish", true, "publish a new message for the given topic");
    publish.setArgName("topic> <message");
    publish.setArgs(2);
    publish.setOptionalArg(true);
    group.addOption(publish);

    Option subscribe = new Option("s", "subscribe", true, "subscribe to a topic");
    subscribe.setArgName("topic> <url");
    subscribe.setArgs(2);
    subscribe.setOptionalArg(true);
    group.addOption(subscribe);

    Option unsubscribe = new Option("u", "unsubscribe", true, "unsubscribe from a topic");
    unsubscribe.setArgName("topic> <url");
    unsubscribe.setArgs(2);
    unsubscribe.setOptionalArg(true);
    group.addOption(unsubscribe);

    Option getSubscribers = new Option("g", "getsubscribers", true, "get subscribers of a topic");
    getSubscribers.setArgName("topic");
    getSubscribers.setArgs(1);
    getSubscribers.setOptionalArg(true);
    group.addOption(getSubscribers);

    Option delete = new Option("d", "delete", true,
            "delete an item (default timeout: 2000ms)\n"
                    + "WARNING: This function can lead to inconsistent data (e.g. "
                    + "deleted items can re-appear). Also when re-creating an item "
                    + "the version before the delete can re-appear.");
    delete.setArgName("key> <[timeout]");
    delete.setArgs(2);
    delete.setOptionalArg(true);
    group.addOption(delete);

    options.addOption(new Option("b", "minibench", false, "run mini benchmark"));

    options.addOption(new Option("lh", "localhost", false,
            "gets the local host's name as known to Java (for debugging purposes)"));

    options.addOptionGroup(group);

    return options;
}