-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/17-NewDotNetToolCommandlet
- Loading branch information
Showing
8 changed files
with
199 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
cli/src/main/java/com/devonfw/tools/ide/commandlet/UninstallCommandlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.io.FileAccess; | ||
import com.devonfw.tools.ide.property.ToolProperty; | ||
|
||
/** | ||
* An internal {@link Commandlet} to uninstall a tool. | ||
*/ | ||
public class UninstallCommandlet extends Commandlet { | ||
|
||
/** The tool to uninstall. */ | ||
public final ToolProperty tool; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param context the {@link IdeContext}. | ||
*/ | ||
public UninstallCommandlet(IdeContext context) { | ||
|
||
super(context); | ||
addKeyword(getName()); | ||
this.tool = add(new ToolProperty("", true, "tool")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return "uninstall"; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
String commandletName = this.tool.getValue().getName(); | ||
Path softwarePath = context.getSoftwarePath().resolve(commandletName); | ||
if (Files.exists(softwarePath)) { | ||
FileAccess fileAccess = context.getFileAccess(); | ||
try { | ||
fileAccess.delete(softwarePath); | ||
this.context.success("Successfully uninstalled " + commandletName); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Couldn't uninstall " + commandletName, e); | ||
} | ||
} else { | ||
this.context.info("An installed version of " + commandletName + " does not exist"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.