Skip to content

Commit db91100

Browse files
Uninstall command
1 parent 2abb02d commit db91100

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.hydev.mcpm.client.arguments.parsers;
2+
3+
import net.sourceforge.argparse4j.impl.Arguments;
4+
import net.sourceforge.argparse4j.inf.Namespace;
5+
import net.sourceforge.argparse4j.inf.Subparser;
6+
import org.hydev.mcpm.client.commands.entries.UninstallController;
7+
import org.hydev.mcpm.client.injector.PluginNotFoundException;
8+
import org.hydev.mcpm.client.uninstall.UninstallResult;
9+
10+
import java.util.function.Consumer;
11+
12+
/**
13+
* Command parser for the uninstallation use case
14+
*
15+
* @author Anushka (https://github.com/aanushkasharma)
16+
* @since 2022-11-27
17+
*/
18+
public record UninstallParser(UninstallController controller) implements CommandParser {
19+
@Override
20+
public String name() {
21+
return "uninstall";
22+
}
23+
24+
@Override
25+
public String description() {
26+
return "Uninstall a plugin from file system";
27+
}
28+
29+
@Override
30+
public void configure(Subparser parser) {
31+
parser.addArgument("name")
32+
.help("Name of the plugin to uninstall");
33+
parser.addArgument("-r", "--recursive").action(Arguments.storeTrue())
34+
.help("Recursively remove orphan dependencies");
35+
}
36+
37+
@Override
38+
public void run(Namespace details, Consumer<String> log)
39+
{
40+
var name = details.getString("name");
41+
try {
42+
// Uninstall
43+
var result = controller.uninstall(name, details.getBoolean("recursive"));
44+
45+
// Print result
46+
if (result.state() == UninstallResult.State.FAILED_TO_DELETE) {
47+
log.accept("&cFailed to delete plugin file");
48+
}
49+
if (result.state() == UninstallResult.State.SUCCESS) {
50+
log.accept("&aPlugin " + name + " uninstalled successfully!");
51+
}
52+
}
53+
catch (PluginNotFoundException e) {
54+
log.accept("&cPlugin of the name " + name + " is not found");
55+
}
56+
}
57+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.hydev.mcpm.client.commands.entries;
2+
3+
import org.hydev.mcpm.client.injector.PluginNotFoundException;
4+
import org.hydev.mcpm.client.uninstall.UninstallBoundary;
5+
import org.hydev.mcpm.client.uninstall.UninstallInput;
6+
import org.hydev.mcpm.client.uninstall.UninstallResult;
7+
8+
/**
9+
* Controller for the uninstallation use case
10+
*
11+
* @author Anushka (https://github.com/aanushkasharma)
12+
* @since 2022-11-27
13+
*/
14+
public record UninstallController(UninstallBoundary boundary) {
15+
/**
16+
* Uninstall a plugin
17+
*
18+
* @param name Name of the plugin
19+
* @param recursive Whether to remove orphan dependencies
20+
* @return Uninstall result
21+
* @throws PluginNotFoundException Plugin not found
22+
*/
23+
public UninstallResult uninstall(String name, boolean recursive) throws PluginNotFoundException {
24+
return boundary.uninstall(new UninstallInput(name, recursive));
25+
}
26+
}

0 commit comments

Comments
 (0)