108 lines
2.3 KiB
Java
108 lines
2.3 KiB
Java
package bootstrap;
|
|
|
|
public abstract class Option {
|
|
|
|
Character shortOption;
|
|
String longOption;
|
|
|
|
boolean isset;
|
|
|
|
public Option(String longOption) {
|
|
this.longOption = longOption;
|
|
}
|
|
public Option(Character shortOption) {
|
|
this.shortOption = shortOption;
|
|
}
|
|
public Option(Character shortOption,String longOption) {
|
|
this.shortOption = shortOption;
|
|
this.longOption = longOption;
|
|
}
|
|
|
|
public Character getShortOption() {
|
|
return this.shortOption;
|
|
}
|
|
public String getLongOption() {
|
|
return this.longOption;
|
|
}
|
|
|
|
public boolean isSet() {
|
|
return this.isset;
|
|
}
|
|
public void Set() {
|
|
this.isset = true;
|
|
}
|
|
public void Unset() {
|
|
this.isset = false;
|
|
}
|
|
|
|
public boolean match(String argument) {
|
|
if (
|
|
((longOption != null) && (argument.startsWith("--")) && (longOption.equals(argument.substring(2)))) ||
|
|
((shortOption != null) && (argument.length()==2) && (argument.charAt(0)=='-') && (argument.charAt(1) == shortOption))
|
|
){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public abstract boolean hasParameters();
|
|
public void addParameter(String parameter) throws IllegalArgumentException{
|
|
throw new IllegalArgumentException(String.format("Option %s dos not accept any parameters",this));
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
if (this.shortOption == null) {
|
|
return "--" + this.longOption;
|
|
} else if (this.longOption == null) {
|
|
return "-" + this.shortOption;
|
|
} else {
|
|
return String.format("[ -%c | --%s ]", shortOption,longOption);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
|
|
OptionType optionType = OptionType.BOOLEAN;
|
|
String name;
|
|
LinkedList<String> parameters = new LinkedList<>();
|
|
|
|
public Option(String name) {
|
|
this.name = name;
|
|
}
|
|
public Option(String name,OptionType OptionType) {
|
|
this.name = name;
|
|
this.optionType = OptionType;
|
|
}
|
|
public Option(String argument,String[] parameters) {
|
|
this.optionType = OptionType.MULTIPLE;
|
|
this.name = argument;
|
|
for (String p : parameters) {
|
|
this.parameters.add(p);
|
|
}
|
|
}
|
|
public Option(String name,OptionType OptionType,String[] parameters) {
|
|
this.name = name;
|
|
for (String p : parameters) {
|
|
this.parameters.add(p);
|
|
}
|
|
}
|
|
|
|
public String getName() {
|
|
return this.name;
|
|
}
|
|
public String[] getParameters() {
|
|
return this.parameters.toArray(new String[0]);
|
|
}
|
|
public String getParameter(int n) {
|
|
return this.parameters.get(n);
|
|
}
|
|
|
|
public void addParameter(String p){
|
|
this.parameters.add(p);
|
|
}
|
|
|
|
*/
|
|
|