Skip to content

Commit

Permalink
#846: fix version shortopt (-v) (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Dec 5, 2024
1 parent a1d4df4 commit 367865d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
24 changes: 8 additions & 16 deletions cli/src/main/java/com/devonfw/tools/ide/commandlet/Commandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class Commandlet {

private Property<?> multiValued;

private String firstKeyword;
private KeywordProperty firstKeyword;

/**
* The constructor.
Expand Down Expand Up @@ -103,21 +103,13 @@ protected void addKeyword(String keyword) {
*/
protected void addKeyword(String keyword, String alias) {

if (this.properties.isEmpty()) {
this.firstKeyword = keyword;
KeywordProperty property = new KeywordProperty(keyword, true, alias);
if (this.firstKeyword == null) {
if (!this.properties.isEmpty()) {
throw new IllegalStateException(property + " must be first property in " + getClass().getSimpleName());
}
this.firstKeyword = property;
}
add(new KeywordProperty(keyword, true, alias));
}

/**
* @param property the keyword {@link Property} to {@link #add(Property) add}.
*/
protected void addKeyword(Property<?> property) {

if (!this.properties.isEmpty()) {
throw new IllegalStateException();
}
this.firstKeyword = property.getNameOrAlias();
add(property);
}

Expand Down Expand Up @@ -169,7 +161,7 @@ private void add(String name, Property<?> property, boolean alias) {
/**
* @return the first keyword of this {@link Commandlet}. Typically the same as {@link #getName() name} but may also differ (e.g. "set" vs. "set-version").
*/
public String getKeyword() {
public KeywordProperty getFirstKeyword() {

return this.firstKeyword;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,17 @@ protected void add(Commandlet commandlet) {
boolean hasRequiredProperty = false;
List<Property<?>> properties = commandlet.getProperties();
int propertyCount = properties.size();
String keyword = commandlet.getKeyword();
KeywordProperty keyword = commandlet.getFirstKeyword();
if (keyword != null) {
this.firstKeywordMap.putIfAbsent(keyword, commandlet);
String name = keyword.getName();
this.firstKeywordMap.putIfAbsent(name, commandlet);
if (name.startsWith("--")) {
this.firstKeywordMap.putIfAbsent(name.substring(2), commandlet);
}
String alias = keyword.getAlias();
if (alias != null) {
this.firstKeywordMap.putIfAbsent(alias, commandlet);
}
}
for (int i = 0; i < propertyCount; i++) {
Property<?> property = properties.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ private void printCommandlets(NlsBundle bundle) {
Args toolcommandlets = new Args();
for (Commandlet cmd : this.context.getCommandletManager().getCommandlets()) {
String key = cmd.getName();
String keyword = cmd.getKeyword();
if ((keyword != null) && !keyword.equals(key)) {
key = key + "(" + keyword + ")";
KeywordProperty keyword = cmd.getFirstKeyword();
if (keyword != null) {
String name = keyword.getName();
if (!name.equals(key)) {
key = key + "(" + keyword + ")";
}
}
if (cmd instanceof ToolCommandlet) {
toolcommandlets.add(key, bundle.get(cmd));
Expand Down

0 comments on commit 367865d

Please sign in to comment.