Skip to content

Commit

Permalink
Implement host renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Ampflower committed Sep 19, 2023
1 parent afe2560 commit 43b4e1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/gay/ampflower/maven/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ public void createHost(String host, Path path) {
hosts.put(host, new Host(path));
}

public boolean renameHost(String host, String name) {
if (hosts.containsKey(name)) {
return false;
}

var renamed = hosts.remove(host);
if (renamed == null) {
return false;
}

hosts.put(name, renamed);

return true;
}

public boolean deleteHost(String host) {
return hosts.remove(host) != null;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/gay/ampflower/maven/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ private static void registerHostCommand(CommandDispatcher<Console> dispatcher) {
logger.info("No such host.");
return 0;
}
}))).then(literal("rename").then(argument("name", string()).executes(ctx -> {
var name = host(ctx, "name");
var old = ctx.getSource().host;

if (ctx.getSource().config.renameHost(old, name)) {
ctx.getSource().host = name;
logger.info("Renamed {} to {}", old, name);
return Command.SINGLE_SUCCESS;
} else {
logger.info("Either {} doesn't exist or {} already exists", old, name);
return 0;
}
}))).then(literal("import").then(literal("legacy").then(argument("name", string())
.then(argument("maven", string()).then(argument("config", greedyString()).executes(ctx -> {
try {
Expand Down

0 comments on commit 43b4e1a

Please sign in to comment.