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

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

Introduction

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

Prototype

public void setValueSeparator(char sep) 

Source Link

Document

Sets the value separator.

Usage

From source file:ca.uhn.hunit.run.TestRunner.java

/**
 * @param args//from   w  w  w. j av a2 s.com
 * @throws URISyntaxException
 * @throws JAXBException
 * @throws ConfigurationException
 * @throws InterfaceWontStartException
 * @throws FileNotFoundException
 * @throws ParseException
 */
public static void main(String[] theArgs) throws URISyntaxException, JAXBException, InterfaceWontStartException,
        ConfigurationException, FileNotFoundException, ParseException {
    Options options = new Options();

    OptionGroup fileOptionGroup = new OptionGroup();
    fileOptionGroup.setRequired(false);

    Option option = new Option("f", "file", true, "The path to the file to load the test battery from");
    option.setValueSeparator('=');
    fileOptionGroup.addOption(option);
    option = new Option("c", "classpath", true, "The classpath path to the file to load the test battery from");
    option.setValueSeparator('=');
    fileOptionGroup.addOption(option);
    options.addOptionGroup(fileOptionGroup);

    OptionGroup uiOptionGroup = new OptionGroup();
    option = new Option("g", "gui", false, "Start hUnit in GUI mode (default)");
    uiOptionGroup.addOption(option);
    option = new Option("x", "text", false, "Start hUnit in Text mode");
    uiOptionGroup.addOption(option);
    options.addOptionGroup(uiOptionGroup);

    option = new Option("t", "tests", true, "A comma separated list of tests to execute (default is all)");
    option.setValueSeparator('=');
    option.setRequired(false);
    options.addOption(option);

    Resource defFile = null;
    CommandLine parser;
    boolean textMode = false;

    try {
        parser = new PosixParser().parse(options, theArgs);

        if (parser.hasOption("f")) {
            defFile = new FileSystemResource(parser.getOptionValue("f"));
        } else if (parser.hasOption("c")) {
            defFile = new ClassPathResource(parser.getOptionValue("c"));
        }

        if (parser.hasOption("x")) {
            textMode = true;
        }
    } catch (Exception e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("java -jar hunit-[version]-jar-with-dependencies.jar [-c FILE|-f FILE] [options]",
                options);

        return;
    }

    String[] testsToExecute = null;

    if (parser.hasOption("t")) {
        testsToExecute = parser.getOptionValue("t").split(",");
    }

    if (textMode) {
        executeInTextMode(defFile, testsToExecute);
    } else {
        executeInGuiMode(defFile, testsToExecute);
    }
}

From source file:cross.io.PropertyFileGenerator.java

/**
 *
 * @param args//  w  w  w .j  a va 2  s. c o m
 */
public static void main(String[] args) {
    Options options = new Options();
    options.addOption("f", true, "base directory for output of files");
    Option provOptions = new Option("p", true,
            "Comma separated list of provider classes to create Properties for");
    provOptions.setRequired(true);
    provOptions.setValueSeparator(',');
    options.addOption(provOptions);
    CommandLineParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    try {
        File basedir = null;
        List<String> providers = Collections.emptyList();
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("f")) {
            basedir = new File(cmd.getOptionValue("f"));
        } else {
            hf.printHelp("java -cp maltcms.jar " + PropertyFileGenerator.class, options);
        }
        if (cmd.hasOption("p")) {
            String[] str = cmd.getOptionValues("p");
            providers = Arrays.asList(str);
        } else {
            hf.printHelp("java -cp maltcms.jar " + PropertyFileGenerator.class, options);
        }
        for (String provider : providers) {
            createProperties(provider, basedir);
        }
    } catch (ParseException ex) {
        Logger.getLogger(PropertyFileGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ca.uhn.hunit.example.MllpHl7v2MessageSwapper.java

public static void main(String[] theArgs) {
    Options options = new Options();

    Option option = new Option("R", true, "Text to substiture in the message");
    option.setArgs(2);/*from w ww .ja  va 2  s  .c o  m*/
    option.setArgName("text=substitution");
    option.setValueSeparator('=');
    option.setRequired(true);
    options.addOption(option);

    option = new Option("p", true, "Number of passes");
    option.setValueSeparator('=');
    option.setRequired(false);
    options.addOption(option);

    CommandLine commandLine;
    int passes;

    try {
        commandLine = new PosixParser().parse(options, theArgs);
        passes = Integer.parseInt(commandLine.getOptionValue("p", "1"));
    } catch (ParseException e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp(
                "java -cp hunit-[version]-jar-with-dependencies.jar ca.uhn.hunit.example.MllpHl7v2MessageSwapper {-Rtext=substitution}... [options]",
                options);

        return;
    }

    Properties substitutions = commandLine.getOptionProperties("R");

    new MllpHl7v2MessageSwapper(true, substitutions, passes).run();
}

From source file:de.topobyte.livecg.ShowVisualization.java

public static void main(String[] args) {
    EnumNameLookup<Visualization> visualizationSwitch = new EnumNameLookup<Visualization>(Visualization.class,
            true);// w w w .jav  a 2s . c  o m

    // @formatter:off
    Options options = new Options();
    OptionHelper.add(options, OPTION_CONFIG, true, false, "path", "config file");
    OptionHelper.add(options, OPTION_VISUALIZATION, true, true, "type",
            "type of visualization. one of <" + VisualizationUtil.getListOfAvailableVisualizations() + ">");
    OptionHelper.add(options, OPTION_STATUS, true, false,
            "status to " + "set the algorithm to. The format depends on the algorithm");
    // @formatter:on

    Option propertyOption = new Option(OPTION_PROPERTIES, "set a special property");
    propertyOption.setArgName("property=value");
    propertyOption.setArgs(2);
    propertyOption.setValueSeparator('=');
    options.addOption(propertyOption);

    CommandLineParser clp = new GnuParser();

    CommandLine line = null;
    try {
        line = clp.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing command line failed: " + e.getMessage());
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }

    String[] extra = line.getArgs();
    if (extra.length == 0) {
        System.out.println("Missing file argument");
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }
    String input = extra[0];

    StringOption argConfig = ArgumentHelper.getString(line, OPTION_CONFIG);
    if (argConfig.hasValue()) {
        String configPath = argConfig.getValue();
        LiveConfig.setPath(configPath);
    }

    StringOption argVisualization = ArgumentHelper.getString(line, OPTION_VISUALIZATION);
    StringOption argStatus = ArgumentHelper.getString(line, OPTION_STATUS);

    Visualization visualization = visualizationSwitch.find(argVisualization.getValue());
    if (visualization == null) {
        System.err.println("Unsupported visualization '" + argVisualization.getValue() + "'");
        System.exit(1);
    }

    System.out.println("Visualization: " + visualization);

    ContentReader contentReader = new ContentReader();
    Content content = null;
    try {
        content = contentReader.read(new File(input));
    } catch (Exception e) {
        System.out.println("Error while reading input file '" + input + "'. Exception type: "
                + e.getClass().getSimpleName() + ", message: " + e.getMessage());
        System.exit(1);
    }

    Properties properties = line.getOptionProperties(OPTION_PROPERTIES);

    ContentLauncher launcher = null;

    switch (visualization) {
    case GEOMETRY: {
        launcher = new ContentDisplayLauncher();
        break;
    }
    case DCEL: {
        launcher = new DcelLauncher();
        break;
    }
    case FREESPACE: {
        launcher = new FreeSpaceChainsLauncher();
        break;
    }
    case DISTANCETERRAIN: {
        launcher = new DistanceTerrainChainsLauncher();
        break;
    }
    case CHAN: {
        launcher = new ChanLauncher();
        break;
    }
    case FORTUNE: {
        launcher = new FortunesSweepLauncher();
        break;
    }
    case MONOTONE_PIECES: {
        launcher = new MonotonePiecesLauncher();
        break;
    }
    case MONOTONE_TRIANGULATION: {
        launcher = new MonotoneTriangulationLauncher();
        break;
    }
    case TRIANGULATION: {
        launcher = new MonotonePiecesTriangulationLauncher();
        break;
    }
    case SPIP: {
        launcher = new ShortestPathInPolygonLauncher();
        break;
    }
    case BUFFER: {
        launcher = new PolygonBufferLauncher();
        break;
    }
    }

    try {
        launcher.launch(content, true);
    } catch (LaunchException e) {
        System.err.println("Unable to start visualization");
        System.err.println("Error message: " + e.getMessage());
        System.exit(1);
    }
}

From source file:de.topobyte.livecg.CreateImage.java

public static void main(String[] args) {
    EnumNameLookup<ExportFormat> exportSwitch = new EnumNameLookup<ExportFormat>(ExportFormat.class, true);

    EnumNameLookup<Visualization> visualizationSwitch = new EnumNameLookup<Visualization>(Visualization.class,
            true);/*w ww .  j a  v  a 2 s . c o  m*/

    // @formatter:off
    Options options = new Options();
    OptionHelper.add(options, OPTION_CONFIG, true, false, "path", "config file");
    OptionHelper.add(options, OPTION_INPUT, true, true, "file", "input geometry file");
    OptionHelper.add(options, OPTION_OUTPUT, true, true, "file", "output file");
    OptionHelper.add(options, OPTION_OUTPUT_FORMAT, true, true, "type",
            "type of output. one of <png,svg,tikz,ipe>");
    OptionHelper.add(options, OPTION_VISUALIZATION, true, true, "type",
            "type of visualization. one of <" + VisualizationUtil.getListOfAvailableVisualizations() + ">");
    OptionHelper.add(options, OPTION_STATUS, true, false,
            "status to " + "set the algorithm to. The format depends on the algorithm");
    // @formatter:on

    Option propertyOption = new Option(OPTION_PROPERTIES, "set a special property");
    propertyOption.setArgName("property=value");
    propertyOption.setArgs(2);
    propertyOption.setValueSeparator('=');
    options.addOption(propertyOption);

    CommandLineParser clp = new GnuParser();

    CommandLine line = null;
    try {
        line = clp.parse(options, args);
    } catch (ParseException e) {
        System.err.println("Parsing command line failed: " + e.getMessage());
        new HelpFormatter().printHelp(HELP_MESSAGE, options);
        System.exit(1);
    }

    StringOption argConfig = ArgumentHelper.getString(line, OPTION_CONFIG);
    if (argConfig.hasValue()) {
        String configPath = argConfig.getValue();
        LiveConfig.setPath(configPath);
    }

    StringOption argInput = ArgumentHelper.getString(line, OPTION_INPUT);
    StringOption argOutput = ArgumentHelper.getString(line, OPTION_OUTPUT);
    StringOption argOutputFormat = ArgumentHelper.getString(line, OPTION_OUTPUT_FORMAT);
    StringOption argVisualization = ArgumentHelper.getString(line, OPTION_VISUALIZATION);
    StringOption argStatus = ArgumentHelper.getString(line, OPTION_STATUS);

    ExportFormat exportFormat = exportSwitch.find(argOutputFormat.getValue());
    if (exportFormat == null) {
        System.err.println("Unsupported output format '" + argOutputFormat.getValue() + "'");
        System.exit(1);
    }

    Visualization visualization = visualizationSwitch.find(argVisualization.getValue());
    if (visualization == null) {
        System.err.println("Unsupported visualization '" + argVisualization.getValue() + "'");
        System.exit(1);
    }

    System.out.println("Visualization: " + visualization);
    System.out.println("Output format: " + exportFormat);

    ContentReader contentReader = new ContentReader();
    Content content = null;
    try {
        content = contentReader.read(new File(argInput.getValue()));
    } catch (Exception e) {
        System.out.println("Error while reading input file '" + argInput.getValue() + "'. Exception type: "
                + e.getClass().getSimpleName() + ", message: " + e.getMessage());
        System.exit(1);
    }

    Properties properties = line.getOptionProperties(OPTION_PROPERTIES);

    double zoom = 1;

    String statusArgument = null;
    if (argStatus.hasValue()) {
        statusArgument = argStatus.getValue();
    }

    VisualizationSetup setup = null;

    switch (visualization) {
    case GEOMETRY: {
        setup = new ContentVisualizationSetup();
        break;
    }
    case DCEL: {
        setup = new DcelVisualizationSetup();
        break;
    }
    case FREESPACE: {
        setup = new FreeSpaceVisualizationSetup();
        break;
    }
    case DISTANCETERRAIN: {
        setup = new DistanceTerrainVisualizationSetup();
        break;
    }
    case CHAN: {
        setup = new ChanVisualizationSetup();
        break;
    }
    case MONOTONE_PIECES: {
        setup = new MonotonePiecesVisualizationSetup();
        break;
    }
    case MONOTONE_TRIANGULATION: {
        setup = new MonotoneTriangulationVisualizationSetup();
        break;
    }
    case TRIANGULATION: {
        setup = new MonotonePiecesTriangulationVisualizationSetup();
        break;
    }
    case BUFFER: {
        setup = new BufferVisualizationSetup();
        break;
    }
    case FORTUNE: {
        setup = new FortunesSweepVisualizationSetup();
        break;
    }
    case SPIP: {
        setup = new ShortestPathVisualizationSetup();
        break;
    }
    }

    if (setup == null) {
        System.err.println("Not yet implemented");
        System.exit(1);
    }

    SetupResult setupResult = setup.setup(content, statusArgument, properties, zoom);

    int width = setupResult.getWidth();
    int height = setupResult.getHeight();

    VisualizationPainter visualizationPainter = setupResult.getVisualizationPainter();

    File output = new File(argOutput.getValue());

    visualizationPainter.setZoom(zoom);

    switch (exportFormat) {
    case IPE: {
        try {
            IpeExporter.exportIpe(output, visualizationPainter, width, height);
        } catch (Exception e) {
            System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName()
                    + ", message: " + e.getMessage());
            System.exit(1);
        }
        break;
    }
    case PNG: {
        try {
            GraphicsExporter.exportPNG(output, visualizationPainter, width, height);
        } catch (IOException e) {
            System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName()
                    + ", message: " + e.getMessage());
            System.exit(1);
        }
        break;
    }
    case SVG: {
        try {
            SvgExporter.exportSVG(output, visualizationPainter, width, height);
        } catch (Exception e) {
            System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName()
                    + ", message: " + e.getMessage());
            System.exit(1);
        }
        break;
    }
    case TIKZ: {
        try {
            TikzExporter.exportTikz(output, visualizationPainter, width, height);
        } catch (Exception e) {
            System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName()
                    + ", message: " + e.getMessage());
            System.exit(1);
        }
        break;
    }
    }
}

From source file:lu.tudor.santec.dicom.gui.header.Dcm2Xml.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();
    Option basedir = new Option("d", true, "store extracted values in files under <basedir>. Cannot be "
            + "specified together with option -o <xmlfile>.");
    basedir.setArgName("basedir");
    opts.addOption(basedir);// ww  w  . j av a  2  s .c o  m
    Option xmlfile = new Option("o", true, "file to write XML to, standard output by default");
    xmlfile.setArgName("xmlfile");
    opts.addOption(xmlfile);
    Option exclude = new Option("x", true,
            "tag (e.g.: 7FE00010) or name (e.g.: PixelData) of attribute " + "to exclude from XML output");
    exclude.setArgName("tag");
    opts.addOption(exclude);
    opts.addOption("X", false, "exclude pixel data from XML output " + "(= shortcut for -x 7FE00010).");
    Option xslurl = new Option("T", true, "transform XML output by applying specified XSL stylesheet.");
    xslurl.setArgName("xslurl");
    opts.addOption(xslurl);
    Option xsltparams = new Option("P", true, "pass specified parameters to the XSL stylesheet.");
    xsltparams.setArgName("param=value,...");
    xsltparams.setValueSeparator('=');
    xsltparams.setArgs(2);
    opts.addOption(xsltparams);
    opts.addOption("I", "incxslt", false, "enable incremental XSLT");
    opts.addOption("c", "compact", false, "suppress additional whitespaces in XML output");
    opts.addOption("C", "comments", false, "include attribute names as comments in XML output");
    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new PosixParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcm2xml: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Dcm2Xml.class.getPackage();
        System.out.println("dcm2xml v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().isEmpty()) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    if (cl.hasOption("o") && cl.hasOption("d"))
        exit("dcm2xml: Option -o <xmlfile> and -d <basedir> are mutual" + "exclusive");
    return cl;
}

From source file:lee.util.jtap.JTapCli.java

public static Options constructOptions() {
    final Options options = new Options();
    options.addOption("h", false, "Print help for this application");
    options.addOption("dumpkeys", false, "Dumps keys for the specified bucket");
    options.addOption("dumpall", false, "Dumps keys and values for the specified bucket");

    Option session = OptionBuilder.withArgName("host,bucket,[password,port]").hasArg()
            .withDescription("host address of membase server, bucket name and optional port if not default.")
            .create("s");
    session.setLongOpt("session");
    session.setValueSeparator(',');
    session.setArgs(4);/*from w ww .j  a  v  a  2 s.co  m*/
    options.addOption(session);

    Option deleteKey = OptionBuilder.withArgName("key").hasArg().withDescription("key to be deleted.")
            .create("dk");
    deleteKey.setLongOpt("deletekey");
    options.addOption(deleteKey);

    Option getKey = OptionBuilder.withArgName("key").hasArg().withDescription("key to be retrieved.")
            .create("gk");
    getKey.setLongOpt("getkey");
    options.addOption(getKey);
    options.addOption("cs", "clearsession", false, "Clear session info from drive.");
    return options;
}

From source file:exm.stc.ui.Main.java

private static Options initOptions() {
    Options opts = new Options();

    Option module = new Option(INCLUDE_FLAG, "include", true, "Add to import search path");
    opts.addOption(module);//from w  ww  . j  a v  a2 s.  co m

    Option arg = new Option(SWIFT_PROG_ARG_FLAG, "arg", true, "Compile-time argument");
    arg.setArgs(2);
    arg.setValueSeparator('=');
    opts.addOption(arg);

    Option preprocArg = new Option(PREPROC_MACRO_FLAG, true, "Preprocessor definition");
    opts.addOption(preprocArg);

    opts.addOption(UPDATE_FLAG, false, "Update output only if out of date");
    return opts;
}

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);/*ww w.  j av  a  2 s . c o  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:net.sf.markov4jmeter.behaviormodelextractor.CmdlOptionFactory.java

/**
 * Creates an option with a specified number of arguments;
 *
 * @param opt//from   w w  w  .j a  v  a2 s  .co m
 *     Short representation of the option (e.g. <code>"s"</code>).
 * @param longOpt
 *     Long representation of the option
 *     (e.g. <code>"source-project"</code>).
 * @param description
 *     Description of the option
 *     (e.g. <code>"Path to source project."</code>).
 * @param isRequired
 *     Flag indicating whether the option is required (as a command-line
 *     argument) or not.
 * @param argName
 *     Display name for the argument value.
 * @param argsNum
 *     Number of arguments; a negative value indicates an infinite sequence
 *     of arguments.
 * @param hasOptionalArg
 *     <code>true</code> if and only if the arguments are optional.
 * @return
 *     An instance of {@link Option} with the specified properties.
 */
public static Option createOption(final String opt, final String longOpt, final String description,
        final boolean isRequired, final String argName, final int argsNum, final boolean hasOptionalArg) {

    final Option option = new Option(opt, longOpt, argsNum != 0 /* hasArg */, description);

    option.setRequired(isRequired);

    if (argsNum != 0) { // argsNum < 0 for infinite sequence of arguments;

        if (argName != null) {
            option.setArgName(argName);
        }
        // negative number of arguments implies an infinite sequence;
        option.setArgs((argsNum < 0) ? Integer.MAX_VALUE : argsNum);

        option.setValueSeparator(CmdlOptionFactory.DEFAULT_VALUE_SEPARATOR);
        option.setOptionalArg(hasOptionalArg);
    }
    return option;
}