[DEV] correct some argument parsing and update remove scenarium
This commit is contained in:
parent
9128ed2dcf
commit
08476ed994
@ -15,7 +15,7 @@
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/scenarium-logger">
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-reggol">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
|
@ -6,6 +6,6 @@ open module org.atriasoft.death {
|
||||
exports org.atriasoft.death;
|
||||
exports org.atriasoft.death.annotation;
|
||||
|
||||
requires transitive io.scenarium.logger;
|
||||
requires transitive org.atriasoft.reggol;
|
||||
requires java.base;
|
||||
}
|
||||
|
@ -50,59 +50,70 @@ public class ArgumentManager {
|
||||
final String parameter = elements[0];
|
||||
String newValue = null;
|
||||
if (!this.properties.existParameter(parameter)) {
|
||||
Log.critical("Parameter Does not exist for '{}'", value);
|
||||
Log.error("Parameter Does not exist for '{}'", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
if (!this.properties.haveParameter(parameter)) {
|
||||
// Boolean value
|
||||
if (elements.length != 1) {
|
||||
Log.critical("Boolean parameter can not have parameters for '{}", value);
|
||||
Log.error("Boolean parameter can not have parameters for '{}", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
} else if (elements.length == 1) {
|
||||
if (iii == this.arguments.size() - 1) {
|
||||
Log.critical("Missing parameters for '{}' (no more arguments)", value);
|
||||
Log.error("Missing parameters for '{}' (no more arguments)", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
newValue = this.arguments.get(iii + 1);
|
||||
if (newValue.startsWith("-")) {
|
||||
Log.critical("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
|
||||
Log.error("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
iii++;
|
||||
} else if (elements.length == 2) {
|
||||
newValue = elements[1];
|
||||
} else {
|
||||
Log.critical("too much parameters for '{}' (only 1 = is authorized)", value);
|
||||
Log.error("too much parameters for '{}' (only 1 = is authorized)", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
this.properties.setParameter(tmp, parameter, newValue);
|
||||
} else if (value.startsWith("-")) {
|
||||
final String[] elements = value.split("=");
|
||||
elements[0] = elements[0].substring(1);
|
||||
Log.warning("find element (-) : {}", Arrays.toString(elements));
|
||||
Log.verbose("find element (-) : {}", Arrays.toString(elements));
|
||||
if (elements[0].length() != 1) {
|
||||
Log.critical("Can not parse alias argument with a size != 1 for '{}'", value);
|
||||
Log.error("Can not parse alias argument with a size != 1 for '{}'", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
final char parameter = elements[0].charAt(0);
|
||||
String newValue = null;
|
||||
if (!this.properties.existParameterAlias(parameter)) {
|
||||
Log.critical("Parameter Does not exist for '{}'", value);
|
||||
Log.error("Parameter Does not exist for '{}'", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
if (!this.properties.haveParameterAlias(parameter)) {
|
||||
// Boolean value
|
||||
if (elements.length != 1) {
|
||||
Log.critical("Boolean parameter can not have parameters for '{}'", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
|
||||
} else if (elements.length == 1) {
|
||||
if (iii == this.arguments.size() - 1) {
|
||||
Log.critical("Missing parameters for '{}' (no more arguments)", value);
|
||||
Log.error("Missing parameters for '{}' (no more arguments)", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
newValue = this.arguments.get(iii + 1);
|
||||
if (newValue.startsWith("-")) {
|
||||
Log.critical("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
|
||||
Log.error("Missing parameters for '{}' (next argument is a parameter (start with '-'))", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
iii++;
|
||||
} else if (elements.length == 2) {
|
||||
newValue = elements[1];
|
||||
} else {
|
||||
Log.critical("too much parameters for '{}' (only 1 = is authorized)", value);
|
||||
Log.error("too much parameters for '{}' (only 1 = is authorized)", value);
|
||||
showHelpAndExitError();
|
||||
}
|
||||
this.properties.setParameterAlias(tmp, parameter, newValue);
|
||||
} else {
|
||||
@ -270,7 +281,25 @@ public class ArgumentManager {
|
||||
return this.actionDetected != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display help of the global elements
|
||||
*/
|
||||
public void showHelp() {
|
||||
this.properties.displayHelp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display help of the global elements and the help of each sub-actions
|
||||
*/
|
||||
public void showHelpAndExitError() {
|
||||
showHelp();
|
||||
System.exit(-2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display help of the global elements and the help of each sub-actions
|
||||
*/
|
||||
public void showHelpFull() {
|
||||
this.properties.displayHelp(true);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.atriasoft.death;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -119,8 +120,23 @@ public class PropertiesInterface {
|
||||
}
|
||||
|
||||
public void displayHelp() {
|
||||
Log.print("Usage:");
|
||||
final StringBuilder applicationLine = new StringBuilder(" ");
|
||||
displayHelp(false);
|
||||
}
|
||||
|
||||
public void displayHelp(final boolean withActions) {
|
||||
|
||||
displayHelp(withActions, 0);
|
||||
}
|
||||
|
||||
public void displayHelp(final boolean withActions, int baseIndent) {
|
||||
if (baseIndent == 0) {
|
||||
Log.print("Usage:");
|
||||
}
|
||||
final StringBuilder applicationLine = new StringBuilder(spaces(4 + baseIndent));
|
||||
if (baseIndent != 0) {
|
||||
baseIndent += 4;
|
||||
Log.print("{}-----------------------------", spaces(baseIndent));
|
||||
}
|
||||
if (this.classCommand != null) {
|
||||
applicationLine.append(this.classCommand).append(" ");
|
||||
} else {
|
||||
@ -130,49 +146,64 @@ public class PropertiesInterface {
|
||||
applicationLine.append("[options] ");
|
||||
}
|
||||
if (this.actions != null && this.actions.getActions().size() != 0) {
|
||||
applicationLine.append("[actions] ...");
|
||||
applicationLine.append("<actions> [options-action]");
|
||||
}
|
||||
Log.print(applicationLine.toString());
|
||||
if (this.classDescription != null) {
|
||||
Log.print("{}", this.classDescription);
|
||||
Log.print("{}{}", spaces(baseIndent), this.classDescription);
|
||||
}
|
||||
if (this.properties.size() != 0) {
|
||||
Log.print(" [options]");
|
||||
Log.print("{} [options]", spaces(baseIndent));
|
||||
for (final FieldProperty prop : this.properties) {
|
||||
final String parameterExpect = haveParameter(prop) ? " [PARAMETER]" : "";
|
||||
if (prop.alias != null && prop.name != null) {
|
||||
Log.print(" -{} / --{}{}", prop.alias, prop.name, parameterExpect);
|
||||
Log.print("{} -{} / --{}{}", spaces(baseIndent), prop.alias, prop.name, parameterExpect);
|
||||
} else if (prop.alias != null) {
|
||||
Log.print(" -{}{}", prop.alias, parameterExpect);
|
||||
Log.print("{} -{}{}", spaces(baseIndent), prop.alias, parameterExpect);
|
||||
} else if (prop.name != null) {
|
||||
Log.print(" --{}{}", prop.name, parameterExpect);
|
||||
Log.print("{} --{}{}", spaces(baseIndent), prop.name, parameterExpect);
|
||||
}
|
||||
if (prop.description != null) {
|
||||
Log.print(" {}", prop.description);
|
||||
Log.print("{} {}", spaces(baseIndent), prop.description);
|
||||
}
|
||||
if (prop.choice != null) {
|
||||
for (final ChoiceElement elem : prop.getChoiceList()) {
|
||||
if (elem.destination() == null) {
|
||||
Log.print(" - {}", elem.origin());
|
||||
Log.print("{} - {}", spaces(baseIndent), elem.origin());
|
||||
} else {
|
||||
Log.print(" - {} ==> {}", elem.origin(), elem.destination());
|
||||
Log.print("{} - {} ==> {}", spaces(baseIndent), elem.origin(), elem.destination());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.actions != null && this.actions.getActions().size() != 0) {
|
||||
Log.print(" [actions]");
|
||||
Log.print("{} <actions>", spaces(baseIndent));
|
||||
final Set<String> actions = this.actions.getActions();
|
||||
|
||||
int sizeOfActions = 0;
|
||||
for (final String action : actions) {
|
||||
sizeOfActions = Math.max(sizeOfActions, action.length());
|
||||
}
|
||||
for (final String action : actions) {
|
||||
final Class<?> clazz = this.actions.getInterface(action);
|
||||
final String description = PropertiesInterface.getDescription(clazz);
|
||||
if (description == null || description.isEmpty()) {
|
||||
Log.print(" {}", action);
|
||||
if (!withActions) {
|
||||
final String description = PropertiesInterface.getDescription(clazz);
|
||||
if (description == null || description.isEmpty()) {
|
||||
Log.print("{} {}", spaces(baseIndent), action);
|
||||
} else {
|
||||
final String emptyString = spaces(sizeOfActions - action.length());
|
||||
Log.print("{} {}:{} {}", spaces(baseIndent), action, emptyString, description);
|
||||
}
|
||||
} else {
|
||||
Log.print(" {}: {}", action, description);
|
||||
final PropertiesInterface tmpInterface = new PropertiesInterface(clazz);
|
||||
tmpInterface.displayHelp(false, baseIndent + 4);
|
||||
}
|
||||
}
|
||||
if (!withActions) {
|
||||
Log.print(" [options-action]");
|
||||
Log.print(" Action have theire specifi help. (add -h or --help after action)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,4 +305,13 @@ public class PropertiesInterface {
|
||||
final FieldProperty property = findFieldAlias(parameter);
|
||||
setParameter(tmp, property.name, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string of spaces that is 'spaces' spaces long.
|
||||
*
|
||||
* @param spaces The number of spaces to add to the string.
|
||||
*/
|
||||
private String spaces(final int spaces) {
|
||||
return CharBuffer.allocate(spaces).toString().replace('\0', ' ');
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.atriasoft.death.internal;
|
||||
|
||||
import io.scenarium.logger.LogLevel;
|
||||
import io.scenarium.logger.Logger;
|
||||
import org.atriasoft.reggol.LogLevel;
|
||||
import org.atriasoft.reggol.Logger;
|
||||
|
||||
public class Log {
|
||||
private static final String LIB_NAME = "death";
|
||||
|
Loading…
x
Reference in New Issue
Block a user