Skip to content

Commit

Permalink
command grab: added --verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jun 9, 2020
1 parent 8618e47 commit 53d00b8
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions groovy/src/main/java/org/jline/script/GroovyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public GroovyCommand(Set<Command> commands, GroovyEngine engine, Printer printer
}
try {
Class.forName("org.apache.ivy.util.Message");
System.setProperty("groovy.grape.report.downloads","true");
System.setProperty("groovy.grape.report.downloads","false");
ivy = true;
} catch (Exception e) {
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public CmdDesc commandDescription(List<String> args) {

@SuppressWarnings("unchecked")
public Object grab(CommandInput input) {
if (input.args().length != 1) {
if (input.args().length > 2) {
throw new IllegalArgumentException("Wrong number of command parameters: " + input.args().length);
}
try {
Expand All @@ -118,15 +118,24 @@ public Object grab(CommandInput input) {
options.put(Printer.INDENTION, 4);
options.put(Printer.VALUE_STYLE, "classpath:/org/jline/groovy/gron.nanorc");
printer.println(options, resp);
} else if (arg.startsWith("-")) {
throw new IllegalArgumentException("Unknown command option: " + arg);
} else {
int artifactId = 0;
if (input.args().length == 2) {
if (input.args()[0].equals("-v") || input.args()[0].equals("--verbose")) {
System.setProperty("groovy.grape.report.downloads","true");
artifactId = 1;
} else if (input.args()[1].equals("-v") || input.args()[1].equals("--verbose")) {
System.setProperty("groovy.grape.report.downloads","true");
} else {
throw new IllegalArgumentException("Unknown command parameters!");
}
}
Map<String, String> artifact = new HashMap<>();
Object xarg = input.xargs()[0];
Object xarg = input.xargs()[artifactId];
if (xarg instanceof String) {
String[] vals = input.args()[0].split(":");
String[] vals = input.args()[artifactId].split(":");
if (vals.length != 3) {
throw new IllegalArgumentException("Invalid command parameter: " + input.args()[0]);
throw new IllegalArgumentException("Invalid command parameter: " + input.args()[artifactId]);
}
artifact.put("group", vals[0]);
artifact.put("module", vals[1]);
Expand All @@ -141,6 +150,8 @@ public Object grab(CommandInput input) {
}
} catch (Exception e) {
saveException(e);
} finally {
System.setProperty("groovy.grape.report.downloads","false");
}
return null;
}
Expand Down Expand Up @@ -218,12 +229,13 @@ private CmdDesc grabCmdDesc() {
Map<String,List<AttributedString>> optDescs = new HashMap<>();
optDescs.put("-? --help", doDescription ("Displays command help"));
optDescs.put("-l --list", doDescription ("List the modules in the cache"));
optDescs.put("-v --verbose", doDescription ("Report downloads"));
CmdDesc out = new CmdDesc(new ArrayList<>(), optDescs);
List<AttributedString> mainDesc = new ArrayList<>();
List<String> info = new ArrayList<>();
info.add("Add maven repository dependencies to classpath");
commandInfos.put(Command.GRAB, info);
mainDesc.add(new AttributedString("grab <group>:<artifact>:<version>"));
mainDesc.add(new AttributedString("grab [OPTIONS] <group>:<artifact>:<version>"));
mainDesc.add(new AttributedString("grab --list"));
out.setMainDesc(mainDesc);
out.setHighlighted(false);
Expand Down

0 comments on commit 53d00b8

Please sign in to comment.