Skip to content

Commit d62c04c

Browse files
committed
cli: move configuration files to .config/jooby.conf fixes #2599
1 parent 9481d17 commit d62c04c

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public class Cli extends Cmd {
7171
} else if ("-V".equalsIgnoreCase(arg) || "--version".equals(arg)) {
7272
ctx.println(ctx.getVersion());
7373
} else {
74-
ctx.println(
75-
"Unknown command or option(s): " + args.stream().collect(Collectors.joining(" ")));
74+
ctx.println("Unknown command or option(s): " + args.stream().collect(Collectors.joining(" ")));
75+
ctx.println(" " + ctx);
7676
ctx.println(spec.commandLine().getUsageMessage());
7777
}
7878
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Version implements CommandLine.IVersionProvider {
3535
private static String doVersion() {
3636
try {
3737
URL url = URI
38-
.create("http://search.maven.org/solrsearch/select?q=+g:io.jooby+a:jooby&start=0&rows=1")
38+
.create("https://search.maven.org/solrsearch/select?q=+g:io.jooby+a:jooby&start=0&rows=1")
3939
.toURL();
4040
URLConnection connection = url.openConnection();
4141
try (Reader in = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)) {
@@ -49,7 +49,7 @@ private static String doVersion() {
4949
return Optional.ofNullable(Version.class.getPackage())
5050
.map(Package::getImplementationVersion)
5151
.filter(Objects::nonNull)
52-
.orElse("2.0.6");
52+
.orElse("2.15.0");
5353
}
5454
}
5555
}

modules/jooby-cli/src/main/java/io/jooby/internal/cli/CommandContextImpl.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.io.InputStream;
1111
import java.io.PrintWriter;
12+
import java.io.Reader;
1213
import java.io.Writer;
1314
import java.nio.charset.StandardCharsets;
1415
import java.nio.file.Files;
@@ -46,6 +47,8 @@ public class CommandContextImpl implements Context {
4647

4748
private Properties versions;
4849

50+
private Path configurationFile;
51+
4952
public CommandContextImpl(LineReader reader, String version) throws IOException {
5053
this.reader = reader;
5154
this.out = reader.getTerminal().writer();
@@ -54,17 +57,27 @@ public CommandContextImpl(LineReader reader, String version) throws IOException
5457
this.templates.setPrettyPrint(true);
5558
this.version = version;
5659

57-
Path file = configurationPath();
60+
// move from .jooby to .config/jooby.conf
61+
configurationFile = Paths.get(System.getProperty("user.home"), ".config", "jooby.conf");
62+
migrateOldConfiguration(Paths.get(System.getProperty("user.home"), ".jooby"), configurationFile);
5863

59-
if (Files.exists(file)) {
60-
configuration = Cli.gson.fromJson(Files.newBufferedReader(file), LinkedHashMap.class);
64+
if (Files.exists(configurationFile)) {
65+
try (Reader in = Files.newBufferedReader(configurationFile)) {
66+
configuration = Cli.gson.fromJson(in, LinkedHashMap.class);
67+
}
6168
} else {
6269
configuration = new LinkedHashMap();
6370
}
6471
}
6572

66-
private Path configurationPath() {
67-
return Paths.get(System.getProperty("user.home"), ".jooby");
73+
private void migrateOldConfiguration(Path from, Path to) throws IOException {
74+
if (Files.exists(from)) {
75+
if (!Files.exists(to.getParent())) {
76+
Files.createDirectories(to.getParent());
77+
}
78+
Files.copy(from, to);
79+
Files.delete(from);
80+
}
6881
}
6982

7083
@Nonnull @Override public String getVersion() {
@@ -83,8 +96,7 @@ private Path configurationPath() {
8396
}
8497
configuration.put("workspace", workspace.toAbsolutePath().toString());
8598
String json = Cli.gson.toJson(configuration);
86-
Files.write(configurationPath(), json.getBytes(StandardCharsets.UTF_8));
87-
99+
Files.write(configurationFile, json.getBytes(StandardCharsets.UTF_8));
88100
}
89101

90102
@Override public void exit(int code) {
@@ -154,4 +166,8 @@ public Map<String, String> getDependencyMap() throws IOException {
154166
}
155167
return result;
156168
}
169+
170+
@Override public String toString() {
171+
return "version: " + getVersion() + "; conf: " + configurationFile;
172+
}
157173
}

0 commit comments

Comments
 (0)