Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#396 Display the tools help output on 'ide help <tool>' #434

Merged
merged 8 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.property.KeywordProperty;
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.tool.ToolCommandlet;
Expand Down Expand Up @@ -215,6 +216,13 @@ public boolean validate() {
return true;
}

/**
* Provide additional usage help of this {@link Commandlet} to the user.
*/
public void printHelp(NlsBundle bundle) {

}

@Override
public String toString() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.devonfw.tools.ide.commandlet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.log.IdeSubLogger;
Expand All @@ -13,6 +9,10 @@
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.version.IdeVersion;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* {@link Commandlet} to print the environment variables.
*/
Expand Down Expand Up @@ -123,6 +123,7 @@ private void printCommandletHelp(NlsBundle bundle, Commandlet cmd) {
this.context.info("");
this.context.info(bundle.get("values"));
values.print();
cmd.printHelp(bundle);
}

private void printCommandlets(NlsBundle bundle) {
Expand Down
23 changes: 23 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.os.MacOsHelper;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
Expand Down Expand Up @@ -344,4 +345,26 @@ public void setEdition(String edition, boolean hint) {
}
}

/**
* Runs the tool's help command to provide the user with usage information.
*/
@Override
public void printHelp(NlsBundle bundle) {

super.printHelp(bundle);
String toolHelpArgs = getToolHelpArguments();
if (toolHelpArgs != null && getInstalledVersion() != null) {
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.WARNING)
.executable(Path.of(getBinaryName())).addArgs(toolHelpArgs);
pc.run(ProcessMode.DEFAULT);
}
}

/**
* @return the tool's specific help command. Usually help, --help or -h. Return null if not applicable.
*/
public String getToolHelpArguments() {

return null;
}
}
7 changes: 7 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/aws/Aws.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;

Expand Down Expand Up @@ -71,4 +72,10 @@ protected void postExtract(Path extractedDir) {
}
}

@Override
public void printHelp(NlsBundle bundle) {

this.context.info("To get detailed help about the usage of the AWS CLI, use \"aws help\"");
}

}
12 changes: 9 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/tool/az/Azure.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.devonfw.tools.ide.tool.az;

import java.nio.file.Path;
import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.nio.file.Path;
import java.util.Set;

/**
* {@link ToolCommandlet} for azure CLI (azure).
*/
Expand Down Expand Up @@ -37,4 +37,10 @@ public void postInstall() {
typeVariables.save();
this.context.getFileAccess().symlink(Path.of("wbin"), getToolPath().resolve("bin"));
}

@Override
public String getToolHelpArguments() {

return "-h";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ protected String getBinaryName() {
return super.getBinaryName();
}
}

@Override
public String getToolHelpArguments() {

return "help";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public DotNet(IdeContext context) {

super(context, "dotnet", Set.of(Tag.DOTNET, Tag.CS));
}

@Override
public String getToolHelpArguments() {

return "help";
}
}
9 changes: 7 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/gh/Gh.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.tool.gh;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.util.Set;

/**
* {@link ToolCommandlet} for github CLI (gh).
*/
Expand All @@ -22,4 +22,9 @@ public Gh(IdeContext context) {
super(context, "gh", Set.of(Tag.CLOUD));
}

@Override
public String getToolHelpArguments() {

return "help";
}
}
10 changes: 8 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/gradle/Gradle.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.devonfw.tools.ide.tool.gradle;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.java.Java;

import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="https://gradle.org/">gradle</a>.
*/
Expand All @@ -30,4 +30,10 @@ public boolean install(boolean silent) {
return super.install(silent);
}

@Override
public String getToolHelpArguments() {

return "--help";
}

}
9 changes: 7 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/helm/Helm.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.tool.helm;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="https://helm.sh/">Helm</a>, the package manager for Kubernetes.
*/
Expand All @@ -21,4 +21,9 @@ public Helm(IdeContext context) {
super(context, "helm", Set.of(Tag.KUBERNETES));
}

@Override
public String getToolHelpArguments() {

return "--help";
}
}
15 changes: 12 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.property.EnumProperty;
import com.devonfw.tools.ide.property.PasswordProperty;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
Expand All @@ -15,8 +16,8 @@
import java.util.Set;

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

Expand Down Expand Up @@ -91,7 +92,8 @@ public void run() {
private void runJasypt(String className) {

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

String jasyptOpts = this.context.getVariables().get("JASYPT_OPTS");
if (jasyptOpts != null && !jasyptOpts.trim().isEmpty()) {
Expand All @@ -110,4 +112,11 @@ private Path resolveJasyptJarPath() {
String installedVersion = getInstalledVersion().toString();
return toolPath.resolve("jasypt-" + installedVersion + ".jar");
}

@Override
public void printHelp(NlsBundle bundle) {

this.context.info(
"To get detailed help about the usage of the jasypt CLI tools, see http://www.jasypt.org/cli.html#");
}
}
9 changes: 7 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/java/Java.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.tool.java;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.util.Set;

/**
* {@link ToolCommandlet} for Java (Java Virtual Machine and Java Development Kit).
*/
Expand All @@ -22,4 +22,9 @@ public Java(IdeContext context) {
super(context, "java", Set.of(Tag.JAVA, Tag.RUNTIME));
}

@Override
public String getToolHelpArguments() {

return "--help";
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.tool.kotlinc;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="https://kotlinlang.org/docs/command-line.html">Kotlin command-line compiler</a>
* (kotlinc).
Expand All @@ -22,4 +22,10 @@ public Kotlinc(IdeContext context) {

super(context, "kotlinc", Set.of(Tag.KOTLIN, Tag.RUNTIME));
}

@Override
public String getToolHelpArguments() {

return "-h";
}
}
12 changes: 10 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class Mvn extends PluginBasedCommandlet {

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

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

private static final String ERROR_SETTINGS_SECURITY_FILE_MESSAGE =
"Failed to create settings security file at: {}. For further details see:\n" + DOCUMENTATION_PAGE_CONF;
Expand Down Expand Up @@ -84,7 +85,8 @@ public void postInstall() {
if (Files.isDirectory(templatesFolderLegacy)) {
templatesFolder = templatesFolderLegacy;
} else {
this.context.warning("No maven templates found. Neither in {} nor in {} - configuration broken", templatesFolder, templatesFolderLegacy);
this.context.warning("No maven templates found. Neither in {} nor in {} - configuration broken",
templatesFolder, templatesFolderLegacy);
hasMvnTemplates = false;
}
}
Expand Down Expand Up @@ -221,4 +223,10 @@ public void installPlugin(PluginDescriptor plugin) {
+ "Please check the plugin properties file in {}", mavenPlugin.getFileName(), mavenPlugin.toAbsolutePath());
}
}

@Override
public String getToolHelpArguments() {

return "-h";
}
}
10 changes: 8 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/tool/node/Node.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.devonfw.tools.ide.tool.node;

import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.nls.NlsBundle;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolCommandlet;

import java.util.Set;

/**
* {@link ToolCommandlet} for <a href="https://nodejs.org/">node</a>.
*/
Expand All @@ -22,4 +23,9 @@ public Node(IdeContext context) {
super(context, "node", Set.of(Tag.JAVA_SCRIPT, Tag.RUNTIME));
}

@Override
public void printHelp(NlsBundle bundle) {

this.context.info("For a list of supported options and arguments, use \"node --help\"");
}
}
6 changes: 6 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/tool/npm/Npm.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ protected void postExtract(Path extractedDir) {
fileAccess.copy(npmBinBath.resolve(npx + cmd), nodeHomePath);
}
}

@Override
public String getToolHelpArguments() {

return "help";
}
}
Loading
Loading