Skip to content

Commit 02b24d3

Browse files
authored
#396: Display the tools help output on 'ide help <tool>' (#434)
1 parent 623ef90 commit 02b24d3

File tree

20 files changed

+160
-30
lines changed

20 files changed

+160
-30
lines changed

cli/src/main/java/com/devonfw/tools/ide/commandlet/Commandlet.java

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.devonfw.tools.ide.commandlet;
22

33
import com.devonfw.tools.ide.context.IdeContext;
4+
import com.devonfw.tools.ide.nls.NlsBundle;
45
import com.devonfw.tools.ide.property.KeywordProperty;
56
import com.devonfw.tools.ide.property.Property;
67
import com.devonfw.tools.ide.tool.ToolCommandlet;
@@ -215,6 +216,13 @@ public boolean validate() {
215216
return true;
216217
}
217218

219+
/**
220+
* Provide additional usage help of this {@link Commandlet} to the user.
221+
*/
222+
public void printHelp(NlsBundle bundle) {
223+
224+
}
225+
218226
@Override
219227
public String toString() {
220228

cli/src/main/java/com/devonfw/tools/ide/commandlet/HelpCommandlet.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.devonfw.tools.ide.commandlet;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.List;
6-
73
import com.devonfw.tools.ide.context.IdeContext;
84
import com.devonfw.tools.ide.log.IdeLogLevel;
95
import com.devonfw.tools.ide.log.IdeSubLogger;
@@ -13,6 +9,10 @@
139
import com.devonfw.tools.ide.property.Property;
1410
import com.devonfw.tools.ide.version.IdeVersion;
1511

12+
import java.util.ArrayList;
13+
import java.util.Collections;
14+
import java.util.List;
15+
1616
/**
1717
* {@link Commandlet} to print the environment variables.
1818
*/
@@ -123,6 +123,7 @@ private void printCommandletHelp(NlsBundle bundle, Commandlet cmd) {
123123
this.context.info("");
124124
this.context.info(bundle.get("values"));
125125
values.print();
126+
cmd.printHelp(bundle);
126127
}
127128

128129
private void printCommandlets(NlsBundle bundle) {

cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.devonfw.tools.ide.context.IdeContext;
77
import com.devonfw.tools.ide.environment.EnvironmentVariables;
88
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
9+
import com.devonfw.tools.ide.nls.NlsBundle;
910
import com.devonfw.tools.ide.os.MacOsHelper;
1011
import com.devonfw.tools.ide.process.ProcessContext;
1112
import com.devonfw.tools.ide.process.ProcessErrorHandling;
@@ -344,4 +345,26 @@ public void setEdition(String edition, boolean hint) {
344345
}
345346
}
346347

348+
/**
349+
* Runs the tool's help command to provide the user with usage information.
350+
*/
351+
@Override
352+
public void printHelp(NlsBundle bundle) {
353+
354+
super.printHelp(bundle);
355+
String toolHelpArgs = getToolHelpArguments();
356+
if (toolHelpArgs != null && getInstalledVersion() != null) {
357+
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING)
358+
.executable(Path.of(getBinaryName())).addArgs(toolHelpArgs);
359+
pc.run(ProcessMode.DEFAULT);
360+
}
361+
}
362+
363+
/**
364+
* @return the tool's specific help command. Usually help, --help or -h. Return null if not applicable.
365+
*/
366+
public String getToolHelpArguments() {
367+
368+
return null;
369+
}
347370
}

cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.devonfw.tools.ide.environment.EnvironmentVariables;
66
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
77
import com.devonfw.tools.ide.io.FileAccess;
8+
import com.devonfw.tools.ide.nls.NlsBundle;
89
import com.devonfw.tools.ide.process.ProcessContext;
910
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
1011

@@ -71,4 +72,10 @@ protected void postExtract(Path extractedDir) {
7172
}
7273
}
7374

75+
@Override
76+
public void printHelp(NlsBundle bundle) {
77+
78+
this.context.info("To get detailed help about the usage of the AWS CLI, use \"aws help\"");
79+
}
80+
7481
}

cli/src/main/java/com/devonfw/tools/ide/tool/az/Azure.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.devonfw.tools.ide.tool.az;
22

3-
import java.nio.file.Path;
4-
import java.util.Set;
5-
63
import com.devonfw.tools.ide.common.Tag;
74
import com.devonfw.tools.ide.context.IdeContext;
85
import com.devonfw.tools.ide.environment.EnvironmentVariables;
96
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
107
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
118
import com.devonfw.tools.ide.tool.ToolCommandlet;
129

10+
import java.nio.file.Path;
11+
import java.util.Set;
12+
1313
/**
1414
* {@link ToolCommandlet} for azure CLI (azure).
1515
*/
@@ -37,4 +37,10 @@ public void postInstall() {
3737
typeVariables.save();
3838
this.context.getFileAccess().symlink(Path.of("wbin"), getToolPath().resolve("bin"));
3939
}
40+
41+
@Override
42+
public String getToolHelpArguments() {
43+
44+
return "-h";
45+
}
4046
}

cli/src/main/java/com/devonfw/tools/ide/tool/docker/Docker.java

+6
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,10 @@ protected String getBinaryName() {
104104
return super.getBinaryName();
105105
}
106106
}
107+
108+
@Override
109+
public String getToolHelpArguments() {
110+
111+
return "help";
112+
}
107113
}

cli/src/main/java/com/devonfw/tools/ide/tool/dotnet/DotNet.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ public DotNet(IdeContext context) {
1616

1717
super(context, "dotnet", Set.of(Tag.DOTNET, Tag.CS));
1818
}
19+
20+
@Override
21+
public String getToolHelpArguments() {
22+
23+
return "help";
24+
}
1925
}

cli/src/main/java/com/devonfw/tools/ide/tool/gh/Gh.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.devonfw.tools.ide.tool.gh;
22

3-
import java.util.Set;
4-
53
import com.devonfw.tools.ide.common.Tag;
64
import com.devonfw.tools.ide.context.IdeContext;
75
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
86
import com.devonfw.tools.ide.tool.ToolCommandlet;
97

8+
import java.util.Set;
9+
1010
/**
1111
* {@link ToolCommandlet} for github CLI (gh).
1212
*/
@@ -22,4 +22,9 @@ public Gh(IdeContext context) {
2222
super(context, "gh", Set.of(Tag.CLOUD));
2323
}
2424

25+
@Override
26+
public String getToolHelpArguments() {
27+
28+
return "help";
29+
}
2530
}

cli/src/main/java/com/devonfw/tools/ide/tool/gradle/Gradle.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.devonfw.tools.ide.tool.gradle;
22

3-
import java.util.Set;
4-
53
import com.devonfw.tools.ide.common.Tag;
64
import com.devonfw.tools.ide.context.IdeContext;
75
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
86
import com.devonfw.tools.ide.tool.ToolCommandlet;
97
import com.devonfw.tools.ide.tool.java.Java;
108

9+
import java.util.Set;
10+
1111
/**
1212
* {@link ToolCommandlet} for <a href="https://gradle.org/">gradle</a>.
1313
*/
@@ -30,4 +30,10 @@ public boolean install(boolean silent) {
3030
return super.install(silent);
3131
}
3232

33+
@Override
34+
public String getToolHelpArguments() {
35+
36+
return "--help";
37+
}
38+
3339
}

cli/src/main/java/com/devonfw/tools/ide/tool/helm/Helm.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.devonfw.tools.ide.tool.helm;
22

3-
import java.util.Set;
4-
53
import com.devonfw.tools.ide.common.Tag;
64
import com.devonfw.tools.ide.context.IdeContext;
75
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
86
import com.devonfw.tools.ide.tool.ToolCommandlet;
97

8+
import java.util.Set;
9+
1010
/**
1111
* {@link ToolCommandlet} for <a href="https://helm.sh/">Helm</a>, the package manager for Kubernetes.
1212
*/
@@ -21,4 +21,9 @@ public Helm(IdeContext context) {
2121
super(context, "helm", Set.of(Tag.KUBERNETES));
2222
}
2323

24+
@Override
25+
public String getToolHelpArguments() {
26+
27+
return "--help";
28+
}
2429
}

cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.devonfw.tools.ide.common.Tag;
44
import com.devonfw.tools.ide.context.IdeContext;
5+
import com.devonfw.tools.ide.nls.NlsBundle;
56
import com.devonfw.tools.ide.property.EnumProperty;
67
import com.devonfw.tools.ide.property.PasswordProperty;
78
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
@@ -15,8 +16,8 @@
1516
import java.util.Set;
1617

1718
/**
18-
* {@link ToolCommandlet} for <a href="http://www.jasypt.org/">Jasypt</a>, The java library which allows to add basic encryption capabilities with minimum
19-
* effort.
19+
* {@link ToolCommandlet} for <a href="http://www.jasypt.org/">Jasypt</a>, The java library which allows to add basic
20+
* encryption capabilities with minimum effort.
2021
*/
2122
public class Jasypt extends LocalToolCommandlet {
2223

@@ -91,7 +92,8 @@ public void run() {
9192
private void runJasypt(String className) {
9293

9394
List<String> arguments = new ArrayList<>(
94-
Arrays.asList("-cp", resolveJasyptJarPath().toString(), className, "password=" + this.masterPassword.getValue(), "input=" + this.secret.getValue()));
95+
Arrays.asList("-cp", resolveJasyptJarPath().toString(), className, "password=" + this.masterPassword.getValue(),
96+
"input=" + this.secret.getValue()));
9597

9698
String jasyptOpts = this.context.getVariables().get("JASYPT_OPTS");
9799
if (jasyptOpts != null && !jasyptOpts.trim().isEmpty()) {
@@ -110,4 +112,11 @@ private Path resolveJasyptJarPath() {
110112
String installedVersion = getInstalledVersion().toString();
111113
return toolPath.resolve("jasypt-" + installedVersion + ".jar");
112114
}
115+
116+
@Override
117+
public void printHelp(NlsBundle bundle) {
118+
119+
this.context.info(
120+
"To get detailed help about the usage of the jasypt CLI tools, see http://www.jasypt.org/cli.html#");
121+
}
113122
}

cli/src/main/java/com/devonfw/tools/ide/tool/java/Java.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.devonfw.tools.ide.tool.java;
22

3-
import java.util.Set;
4-
53
import com.devonfw.tools.ide.common.Tag;
64
import com.devonfw.tools.ide.context.IdeContext;
75
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
86
import com.devonfw.tools.ide.tool.ToolCommandlet;
97

8+
import java.util.Set;
9+
1010
/**
1111
* {@link ToolCommandlet} for Java (Java Virtual Machine and Java Development Kit).
1212
*/
@@ -22,4 +22,9 @@ public Java(IdeContext context) {
2222
super(context, "java", Set.of(Tag.JAVA, Tag.RUNTIME));
2323
}
2424

25+
@Override
26+
public String getToolHelpArguments() {
27+
28+
return "--help";
29+
}
2530
}

cli/src/main/java/com/devonfw/tools/ide/tool/kotlinc/Kotlinc.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.devonfw.tools.ide.tool.kotlinc;
22

3-
import java.util.Set;
4-
53
import com.devonfw.tools.ide.common.Tag;
64
import com.devonfw.tools.ide.context.IdeContext;
75
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
86
import com.devonfw.tools.ide.tool.ToolCommandlet;
97

8+
import java.util.Set;
9+
1010
/**
1111
* {@link ToolCommandlet} for <a href="https://kotlinlang.org/docs/command-line.html">Kotlin command-line compiler</a>
1212
* (kotlinc).
@@ -22,4 +22,10 @@ public Kotlinc(IdeContext context) {
2222

2323
super(context, "kotlinc", Set.of(Tag.KOTLIN, Tag.RUNTIME));
2424
}
25+
26+
@Override
27+
public String getToolHelpArguments() {
28+
29+
return "-h";
30+
}
2531
}

cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class Mvn extends PluginBasedCommandlet {
4747

4848
private static final String DOCUMENTATION_PAGE_CONF = "https://github.com/devonfw/IDEasy/blob/main/documentation/conf.adoc";
4949

50-
private static final String ERROR_SETTINGS_FILE_MESSAGE = "Failed to create settings file at: {}. For further details see:\n" + DOCUMENTATION_PAGE_CONF;
50+
private static final String ERROR_SETTINGS_FILE_MESSAGE =
51+
"Failed to create settings file at: {}. For further details see:\n" + DOCUMENTATION_PAGE_CONF;
5152

5253
private static final String ERROR_SETTINGS_SECURITY_FILE_MESSAGE =
5354
"Failed to create settings security file at: {}. For further details see:\n" + DOCUMENTATION_PAGE_CONF;
@@ -84,7 +85,8 @@ public void postInstall() {
8485
if (Files.isDirectory(templatesFolderLegacy)) {
8586
templatesFolder = templatesFolderLegacy;
8687
} else {
87-
this.context.warning("No maven templates found. Neither in {} nor in {} - configuration broken", templatesFolder, templatesFolderLegacy);
88+
this.context.warning("No maven templates found. Neither in {} nor in {} - configuration broken",
89+
templatesFolder, templatesFolderLegacy);
8890
hasMvnTemplates = false;
8991
}
9092
}
@@ -221,4 +223,10 @@ public void installPlugin(PluginDescriptor plugin) {
221223
+ "Please check the plugin properties file in {}", mavenPlugin.getFileName(), mavenPlugin.toAbsolutePath());
222224
}
223225
}
226+
227+
@Override
228+
public String getToolHelpArguments() {
229+
230+
return "-h";
231+
}
224232
}

cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.devonfw.tools.ide.tool.node;
22

3-
import java.util.Set;
4-
53
import com.devonfw.tools.ide.common.Tag;
64
import com.devonfw.tools.ide.context.IdeContext;
5+
import com.devonfw.tools.ide.nls.NlsBundle;
76
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
87
import com.devonfw.tools.ide.tool.ToolCommandlet;
98

9+
import java.util.Set;
10+
1011
/**
1112
* {@link ToolCommandlet} for <a href="https://nodejs.org/">node</a>.
1213
*/
@@ -22,4 +23,9 @@ public Node(IdeContext context) {
2223
super(context, "node", Set.of(Tag.JAVA_SCRIPT, Tag.RUNTIME));
2324
}
2425

26+
@Override
27+
public void printHelp(NlsBundle bundle) {
28+
29+
this.context.info("For a list of supported options and arguments, use \"node --help\"");
30+
}
2531
}

cli/src/main/java/com/devonfw/tools/ide/tool/npm/Npm.java

+6
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ protected void postExtract(Path extractedDir) {
5353
fileAccess.copy(npmBinBath.resolve(npx + cmd), nodeHomePath);
5454
}
5555
}
56+
57+
@Override
58+
public String getToolHelpArguments() {
59+
60+
return "help";
61+
}
5662
}

0 commit comments

Comments
 (0)