Skip to content

Commit

Permalink
simplify FlagProperty usage and allow ToolCommandlets to have long op…
Browse files Browse the repository at this point in the history
…tions (devonfw#644)
  • Loading branch information
hohwille authored Oct 24, 2024
1 parent 4673d68 commit ff07365
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
25 changes: 21 additions & 4 deletions cli/src/main/java/com/devonfw/tools/ide/cli/CliArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class CliArguments implements Iterator<CliArgument> {

private boolean endOptions;

private boolean splitShortOpts;

/**
* The constructor.
*
Expand All @@ -30,23 +32,38 @@ public CliArguments(String... args) {
*/
public CliArguments(CliArgument arg) {

this(arg, false);
this(arg, false, true);
}

CliArguments(CliArgument arg, boolean endOpts) {
CliArguments(CliArgument arg, boolean endOpts, boolean splitShortOpts) {

super();
this.initialArgument = arg;
this.endOptions = endOpts;
this.splitShortOpts = splitShortOpts;
setCurrent(arg);
}

/**
* Marks the end of the options so no further {@link CliArgument#getNext(boolean) option splitting} will be performed.
*
* @see #stopSplitShortOptions()
*/
public void endOptions() {

this.endOptions = true;
this.splitShortOpts = false;
}

/**
* Stops splitting of short options.
*
* @see CliArgument#getNext(boolean)
* @see #endOptions()
*/
public void stopSplitShortOptions() {

this.splitShortOpts = false;
}

/**
Expand Down Expand Up @@ -106,7 +123,7 @@ public boolean hasNext() {
public CliArgument next() {

if (!this.currentArg.isEnd()) {
setCurrent(this.currentArg.getNext(!this.endOptions));
setCurrent(this.currentArg.getNext(this.splitShortOpts));
}
return this.currentArg;
}
Expand All @@ -116,7 +133,7 @@ public CliArgument next() {
*/
public CliArguments copy() {

return new CliArguments(this.currentArg, this.endOptions);
return new CliArguments(this.currentArg, this.endOptions, this.splitShortOpts);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CreateCommandlet(IdeContext context) {

super(context);
this.newProject = add(new StringProperty("", true, "project"));
this.skipRepositories = add(new FlagProperty("--skip-repositories", false, null));
this.skipRepositories = add(new FlagProperty("--skip-repositories"));
add(this.settingsRepo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public EditionGetCommandlet(IdeContext context) {
super(context);
addKeyword(getName());
this.tool = add(new ToolProperty("", true, "tool"));
this.configured = add(new FlagProperty("--configured", false, null));
this.installed = add(new FlagProperty("--installed", false, null));
this.configured = add(new FlagProperty("--configured"));
this.installed = add(new FlagProperty("--installed"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public EnvironmentCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
this.bash = add(new FlagProperty("--bash", false, null));
this.bash = add(new FlagProperty("--bash"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public VersionGetCommandlet(IdeContext context) {
super(context);
addKeyword(getName());
this.tool = add(new ToolProperty("", true, "tool"));
this.configured = add(new FlagProperty("--configured", false, null));
this.installed = add(new FlagProperty("--installed", false, null));
this.configured = add(new FlagProperty("--configured"));
this.installed = add(new FlagProperty("--installed"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public ValidationResult apply(CliArguments arguments, Commandlet cmd, Completion
}
}
if ((property != null) && property.isValue() && property.isMultiValued()) {
arguments.endOptions();
arguments.stopSplitShortOptions();
}
}
boolean matches = currentProperty.apply(arguments, this, cmd, collector);
Expand Down
19 changes: 19 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/property/FlagProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
*/
public class FlagProperty extends BooleanProperty {

/**
* The constructor.
*
* @param name the {@link #getName() property name}.
*/
public FlagProperty(String name) {
this(name, false);
}

/**
* The constructor.
*
* @param name the {@link #getName() property name}.
* @param required the {@link #isRequired() required flag}.
*/
public FlagProperty(String name, boolean required) {
this(name, required, null);
}

/**
* The constructor.
*
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/resources/nls/Help_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ opt.--force=Aktiviert den Force-Modus (Erzwingen).
opt.--locale=Die Spracheinstellungen (z.B. 'en' für Englisch).
opt.--offline=Aktiviert den Offline-Modus (Überspringt Aktualisierungen oder git pull, schlägt fehl bei Downloads or git clone).
opt.--quiet=Deaktiviert Info Logging ( nur success, warning und error).
opt.--skip-repositories=überspringt die Einrichtung der Repositories.
opt.--skip-tools=überspringt die Installation/Aktualisierung der Tools.
opt.--skip-repositories=Überspringt die Einrichtung der Repositories.
opt.--skip-tools=Überspringt die Installation/Aktualisierung der Tools.
opt.--trace=Aktiviert Trace-Ausgaben (detaillierte Fehleranalyse).
opt.--version=Zeigt die IDE Version an und beendet das Programm.
options=Optionen:
Expand Down

0 comments on commit ff07365

Please sign in to comment.