2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
7 import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
8 import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
11 * This class represents commandline option which accepts exactly one parameter
14 public class StringOption extends Option<String, StringOption> {
16 public final String defaultValue;
18 public StringOption(final String description) {
19 super(description, ParameterCount.ONE);
22 public StringOption(final String description, String defaultValue) {
23 super(description, ParameterCount.ONE);
24 this.defaultValue = defaultValue;
25 this.setPresent(true);
29 public java.lang.String describeFormat() {
34 public String getValue() {
36 if (parameters.isEmpty() && (defaultValue != null)) return defaultValue;
38 if (parameters.size() == 1) return parameters.get(0);
40 throw new RuntimeException("Parameter " + description
41 + " shall have exactly 1 argument.");
45 public boolean isValid(final java.lang.String value) {