Skip to content

Commit

Permalink
Permit CLI --open-group to accept a substring of a group name as a co…
Browse files Browse the repository at this point in the history
…nvenience.
  • Loading branch information
jglick committed Nov 17, 2017
1 parent 5d0b08c commit 62e8701
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,14 @@

package org.netbeans.modules.project.ui.groups;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.PrintStream;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ui.OpenProjects;
import org.netbeans.api.sendopts.CommandException;
import org.netbeans.spi.sendopts.Env;
import org.openide.util.NbBundle.Messages;
import static org.netbeans.modules.project.ui.groups.Bundle.*;
import org.netbeans.spi.sendopts.Arg;
import org.netbeans.spi.sendopts.Description;
import org.netbeans.spi.sendopts.ArgsProcessor;
import org.openide.util.Exceptions;
import org.openide.util.RequestProcessor;

public class GroupOptionProcessor implements ArgsProcessor {
@Arg(longName="open-group")
Expand All @@ -44,7 +36,7 @@ public class GroupOptionProcessor implements ArgsProcessor {
)
@Messages({
"GroupOptionProcessor.open.name=--open-group NAME",
"GroupOptionProcessor.open.desc=open a project group by name"
"GroupOptionProcessor.open.desc=open a project group by ID or name (or unique substring)"
})
public String openOption;
@Arg(longName="close-group")
Expand All @@ -68,14 +60,26 @@ public class GroupOptionProcessor implements ArgsProcessor {
})
@Override public void process(Env env) throws CommandException {
if (openOption != null) {
Group found = null;
for (Group g : Group.allGroups()) {
if (g.id.equals(openOption) || g.getName().equals(openOption)) {
supressWinsysLazyLoading();
Group.setActiveGroup(g, false);
return;
found = g;
break;
}
}
throw new CommandException(2, GroupOptionProcessor_no_such_group(openOption));
if (found == null) {
for (Group g : Group.allGroups()) {
if (g.id.contains(openOption) || g.getName().contains(openOption)) {
found = g;
break;
}
}
}
if (found == null) {
throw new CommandException(2, GroupOptionProcessor_no_such_group(openOption));
}
supressWinsysLazyLoading();
Group.setActiveGroup(found, false);
} else if (closeOption) {
supressWinsysLazyLoading();
Group.setActiveGroup(null, false);
Expand Down

0 comments on commit 62e8701

Please sign in to comment.