All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ow2.mind.cli.CmdPathOption Maven / Gradle / Ivy

The newest version!

package org.ow2.mind.cli;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * An option that have a value and that may be specified several time on a
 * command-line. The resulting option value is the concatenation of the values
 * of each occurrence of this option separated by {@link File#pathSeparator}.
 */
public class CmdPathOption extends CmdAppendOption {

  /**
   * @param id the identifier of this option.
   * @param shortName the short name of the option. Must have one and only one
   *          character. May be null.
   * @param longName the long name of the option. Must have more than one
   *          character. May be null.
   * @param description the description of the option (used to generate help
   *          message).
   * @param argDesc the description of the argument value (used to generate help
   *          message).
   */
  public CmdPathOption(final String id, final String shortName,
      final String longName, final String description, final String argDesc) {
    super(id, shortName, longName, description, argDesc, null,
        File.pathSeparator);
  }

  /**
   * @param commandLine a command-line
   * @return the value of this option on the given command-line as a list of
   *         String, or null.
   */
  public List getPathValue(final CommandLine commandLine) {
    final String value = getValue(commandLine);
    if (value == null)
      return null;
    else
      return parsePathList(value);
  }

  protected List parsePathList(String paths) {
    final List l = new ArrayList();
    int index = paths.indexOf(File.pathSeparatorChar);
    while (index != -1) {
      l.add(paths.substring(0, index));
      paths = paths.substring(index + 1);
      index = paths.indexOf(File.pathSeparatorChar);
    }
    l.add(paths);
    return l;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy