Skip to content

Commit d19c1b4

Browse files
committed
jooby-cli: allow to create workspace directory
fix #2109
1 parent b9098a7 commit d19c1b4

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

modules/jooby-cli/src/main/java/io/jooby/cli/SetCmd.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
*/
66
package io.jooby.cli;
77

8-
import picocli.CommandLine;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.regex.Matcher;
912

1013
import javax.annotation.Nonnull;
11-
import java.nio.file.Path;
14+
15+
import picocli.CommandLine;
1216

1317
/**
1418
* Set/configure options used by the tool (for now is just for workspace).
@@ -20,12 +24,31 @@ public class SetCmd extends Cmd {
2024
@CommandLine.Spec
2125
private CommandLine.Model.CommandSpec spec;
2226

23-
@CommandLine.Option(names = {"-w", "--workspace"}, description = "Save the workspace directory. Projects are going to be created here")
24-
private Path workspace;
27+
@CommandLine.Option(names = {"-w",
28+
"--workspace"}, description = "Save the workspace directory. Projects are going to be created here")
29+
private String workspace;
30+
31+
@CommandLine.Option(names = {"-f",
32+
"--force"}, description = "Force creation of workspace")
33+
private boolean force;
2534

2635
@Override public void run(@Nonnull Context ctx) throws Exception {
2736
if (workspace != null) {
28-
ctx.setWorkspace(workspace);
37+
Path path = Paths.get(
38+
workspace.replaceFirst("^~", Matcher.quoteReplacement(System.getProperty("user.home"))))
39+
.normalize()
40+
.toAbsolutePath();
41+
if (Files.exists(path)) {
42+
ctx.setWorkspace(path);
43+
} else {
44+
if (force) {
45+
Files.createDirectories(path);
46+
ctx.setWorkspace(path);
47+
} else {
48+
ctx.println("Directory doesn't exist: " + path);
49+
ctx.println("Use -f to force directory creation");
50+
}
51+
}
2952
} else {
3053
ctx.println(spec.commandLine().getUsageMessage());
3154
}

modules/jooby-kafka/src/main/java/io/jooby/kafka/KafkaHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import io.jooby.ServiceKey;
1414
import io.jooby.ServiceRegistry;
1515

16-
class KafkaHelper {
16+
final class KafkaHelper {
17+
18+
private KafkaHelper() {
19+
}
1720

1821
public static void install(Jooby application, String key,
1922
Function<Properties, AutoCloseable> factory) {

0 commit comments

Comments
 (0)