Rework help command
- Change help command output to get templated using model classes. - Remove things around ParameterDescription as those are replaced with template classes. - Fixes for native configs. - For now availability and aliases are removed from help to get back in better form. - Aliases has been partly introduced to structure. - Fixes #422
This commit is contained in:
committed by
GitHub
parent
eed1d84653
commit
bd9ab62013
@@ -79,84 +79,88 @@ public class StandardMethodTargetRegistrar implements MethodTargetRegistrar, App
|
||||
keys = new String[] { Utils.unCamelify(method.getName()) };
|
||||
}
|
||||
String group = getOrInferGroup(method);
|
||||
for (String key : keys) {
|
||||
log.debug("Registering with keys='{}' key='{}'", keys, key);
|
||||
Supplier<Availability> availabilityIndicator = findAvailabilityIndicator(keys, bean, method);
|
||||
|
||||
Builder builder = CommandRegistration.builder()
|
||||
.command(key)
|
||||
.group(group)
|
||||
.description(shellMapping.value())
|
||||
.interactionMode(shellMapping.interactionMode())
|
||||
.availability(availabilityIndicator);
|
||||
String key = keys[0];
|
||||
log.debug("Registering with keys='{}' key='{}'", keys, key);
|
||||
Supplier<Availability> availabilityIndicator = findAvailabilityIndicator(keys, bean, method);
|
||||
|
||||
InvocableHandlerMethod ihm = new InvocableHandlerMethod(bean, method);
|
||||
for (MethodParameter mp : ihm.getMethodParameters()) {
|
||||
Builder builder = CommandRegistration.builder()
|
||||
.command(key)
|
||||
.group(group)
|
||||
.description(shellMapping.value())
|
||||
.interactionMode(shellMapping.interactionMode())
|
||||
.availability(availabilityIndicator);
|
||||
|
||||
ShellOption so = mp.getParameterAnnotation(ShellOption.class);
|
||||
log.debug("Registering with mp='{}' so='{}'", mp, so);
|
||||
if (so != null) {
|
||||
List<String> longNames = new ArrayList<>();
|
||||
List<Character> shortNames = new ArrayList<>();
|
||||
if (!ObjectUtils.isEmpty(so.value())) {
|
||||
Arrays.asList(so.value()).stream().forEach(o -> {
|
||||
String stripped = StringUtils.trimLeadingCharacter(o, '-');
|
||||
log.debug("Registering o='{}' stripped='{}'", o, stripped);
|
||||
if (o.length() == stripped.length() + 2) {
|
||||
longNames.add(stripped);
|
||||
}
|
||||
else if (o.length() == stripped.length() + 1 && stripped.length() == 1) {
|
||||
shortNames.add(stripped.charAt(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// ShellOption value not defined
|
||||
mp.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
|
||||
String longName = mp.getParameterName();
|
||||
Class<?> parameterType = mp.getParameterType();
|
||||
if (longName != null) {
|
||||
log.debug("Using mp='{}' longName='{}' parameterType='{}'", mp, longName, parameterType);
|
||||
longNames.add(longName);
|
||||
for (int i = 1; i < keys.length; i++) {
|
||||
builder.withAlias().command(keys[i]).group(group);
|
||||
}
|
||||
|
||||
InvocableHandlerMethod ihm = new InvocableHandlerMethod(bean, method);
|
||||
for (MethodParameter mp : ihm.getMethodParameters()) {
|
||||
|
||||
ShellOption so = mp.getParameterAnnotation(ShellOption.class);
|
||||
log.debug("Registering with mp='{}' so='{}'", mp, so);
|
||||
if (so != null) {
|
||||
List<String> longNames = new ArrayList<>();
|
||||
List<Character> shortNames = new ArrayList<>();
|
||||
if (!ObjectUtils.isEmpty(so.value())) {
|
||||
Arrays.asList(so.value()).stream().forEach(o -> {
|
||||
String stripped = StringUtils.trimLeadingCharacter(o, '-');
|
||||
log.debug("Registering o='{}' stripped='{}'", o, stripped);
|
||||
if (o.length() == stripped.length() + 2) {
|
||||
longNames.add(stripped);
|
||||
}
|
||||
}
|
||||
if (!longNames.isEmpty() || !shortNames.isEmpty()) {
|
||||
log.debug("Registering longNames='{}' shortNames='{}'", longNames, shortNames);
|
||||
OptionSpec optionSpec = builder.withOption()
|
||||
.type(mp.getParameterType())
|
||||
.longNames(longNames.toArray(new String[0]))
|
||||
.shortNames(shortNames.toArray(new Character[0]))
|
||||
.position(mp.getParameterIndex())
|
||||
.description(so.help());
|
||||
if (so.arity() > -1) {
|
||||
optionSpec.arity(0, so.arity());
|
||||
else if (o.length() == stripped.length() + 1 && stripped.length() == 1) {
|
||||
shortNames.add(stripped.charAt(0));
|
||||
}
|
||||
if (!ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NONE)
|
||||
&& !ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NULL)) {
|
||||
optionSpec.defaultValue(so.defaultValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// ShellOption value not defined
|
||||
mp.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
|
||||
String longName = mp.getParameterName();
|
||||
Class<?> parameterType = mp.getParameterType();
|
||||
if (longName != null) {
|
||||
log.debug("Using mp='{}' longName='{}' parameterType='{}'", mp, longName, parameterType);
|
||||
builder.withOption()
|
||||
.longNames(longName)
|
||||
.type(parameterType)
|
||||
.required()
|
||||
.position(mp.getParameterIndex());
|
||||
longNames.add(longName);
|
||||
}
|
||||
}
|
||||
if (!longNames.isEmpty() || !shortNames.isEmpty()) {
|
||||
log.debug("Registering longNames='{}' shortNames='{}'", longNames, shortNames);
|
||||
OptionSpec optionSpec = builder.withOption()
|
||||
.type(mp.getParameterType())
|
||||
.longNames(longNames.toArray(new String[0]))
|
||||
.shortNames(shortNames.toArray(new Character[0]))
|
||||
.position(mp.getParameterIndex())
|
||||
.description(so.help());
|
||||
if (so.arity() > -1) {
|
||||
optionSpec.arity(0, so.arity());
|
||||
}
|
||||
if (!ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NONE)
|
||||
&& !ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NULL)) {
|
||||
optionSpec.defaultValue(so.defaultValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
builder.withTarget().method(bean, method);
|
||||
|
||||
CommandRegistration registration = builder.build();
|
||||
registry.register(registration);
|
||||
else {
|
||||
mp.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
|
||||
String longName = mp.getParameterName();
|
||||
Class<?> parameterType = mp.getParameterType();
|
||||
if (longName != null) {
|
||||
log.debug("Using mp='{}' longName='{}' parameterType='{}'", mp, longName, parameterType);
|
||||
builder.withOption()
|
||||
.longNames(longName)
|
||||
.type(parameterType)
|
||||
.required()
|
||||
.position(mp.getParameterIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
builder.withTarget().method(bean, method);
|
||||
|
||||
CommandRegistration registration = builder.build();
|
||||
registry.register(registration);
|
||||
}, method -> method.getAnnotation(ShellMethod.class) != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
"includes": [
|
||||
{
|
||||
"pattern": "completion/.*"
|
||||
},
|
||||
{
|
||||
"pattern": "template/.*.st"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<if(buildVersion)>
|
||||
<("Build Version"); format="list-key">: <buildVersion; format="list-value">
|
||||
<endif>
|
||||
<if(buildGroup)>
|
||||
<("Build Group"); format="list-key">: <buildGroup; format="list-value">
|
||||
<endif>
|
||||
<if(buildArtifact)>
|
||||
<("Build Artifact"); format="list-key">: <buildArtifact; format="list-value">
|
||||
<endif>
|
||||
<if(buildName)>
|
||||
<("Build Name"); format="list-key">: <buildName; format="list-value">
|
||||
<endif>
|
||||
<if(buildTime)>
|
||||
<("Build Time"); format="list-key">: <buildTime; format="list-value">
|
||||
<endif>
|
||||
<if(gitShortCommitId)>
|
||||
<("Git Short Commit Id"); format="list-key">: <gitShortCommitId; format="list-value">
|
||||
<endif>
|
||||
<if(gitCommitId)>
|
||||
<("Git Commit Id"); format="list-key">: <gitCommitId; format="list-value">
|
||||
<endif>
|
||||
<if(gitBranch)>
|
||||
<("Git Branch"); format="list-key">: <gitBranch; format="list-value">
|
||||
<endif>
|
||||
<if(gitCommitTime)>
|
||||
<("Git Commit Time"); format="list-key">: <gitCommitTime; format="list-value">
|
||||
<endif>
|
||||
Reference in New Issue
Block a user