Skip to content

Commit 2e64c0f

Browse files
committed
Add CLI workflow tests
1 parent 748dd5a commit 2e64c0f

File tree

8 files changed

+428
-32
lines changed

8 files changed

+428
-32
lines changed

.github/workflows/publish-release.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ on:
77
- release
88

99
jobs:
10-
test:
11-
name: Test
12-
permissions:
13-
contents: read
14-
uses: ./.github/workflows/func-test.yml
1510
build-jar:
1611
name: Build Jar
17-
needs: test
1812
permissions:
1913
contents: read
2014
uses: ./.github/workflows/func-build-jar.yml

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,20 @@ You can also run directly via Gradle during development:
6868

6969
## Quick Start
7070

71-
All state is stored under `~/.jdbcli/`:
71+
All state is stored under `~/.jdbcli/` by default.
7272

7373
| Path | Contents |
7474
|---|---|
7575
| `~/.jdbcli/dbs/` | Database descriptors (JSON) |
7676
| `~/.jdbcli/drivers/` | Downloaded JDBC driver JARs |
7777
| `~/.jdbcli/profiles/` | Connection profiles (JSON) |
7878

79+
Override with `-Djdbcli.home=<path>`:
80+
81+
```bash
82+
java -Djdbcli.home=/opt/jdbcli -jar jdbcli.jar db list
83+
```
84+
7985
### 1. Browse built-in database descriptors
8086

8187
```bash

src/main/java/io/github/denyshorman/jdbcli/cli/DbCommand.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.denyshorman.jdbcli.config.DbDescriptor;
44
import io.github.denyshorman.jdbcli.descriptor.DbDescriptorLoader;
5+
import io.github.denyshorman.jdbcli.exception.JdbcliException;
56
import io.github.denyshorman.jdbcli.util.FileSystemUtil;
67
import io.github.denyshorman.jdbcli.util.JsonUtil;
78
import org.slf4j.Logger;
@@ -56,11 +57,11 @@ public void list() {
5657
public void show(@Parameters(index = "0", paramLabel = "<id>", description = "Descriptor ID (e.g. postgres, sqlserver, oracle, mongodb)") String dbName) {
5758
var db = DbDescriptorLoader.load(dbName);
5859

59-
if (db != null) {
60-
System.out.println(JsonUtil.MAPPER.writeValueAsString(db));
61-
} else {
62-
LOGGER.error("Database not found: {}", dbName);
60+
if (db == null) {
61+
throw new JdbcliException("Database not found: " + dbName);
6362
}
63+
64+
System.out.println(JsonUtil.MAPPER.writeValueAsString(db));
6465
}
6566

6667
@Command(

src/main/java/io/github/denyshorman/jdbcli/cli/MainCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
" 3. jdbcli profile init --db mydb --name dev # create a connection profile",
1919
" 4. jdbcli query --profile dev --sql \"SELECT 1\" # run a query",
2020
"",
21+
"Set -Djdbcli.home=<path> to use a custom home directory instead of ~/.jdbcli.",
2122
"Set JDBCLI_DEBUG=1 to print full stack traces on error.",
2223
},
2324
subcommands = {

src/main/java/io/github/denyshorman/jdbcli/cli/ProfileCommand.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
import io.github.denyshorman.jdbcli.config.Profile;
55
import io.github.denyshorman.jdbcli.config.SafetyConfig;
66
import io.github.denyshorman.jdbcli.descriptor.DbDescriptorLoader;
7+
import io.github.denyshorman.jdbcli.driver.DriverInstaller;
78
import io.github.denyshorman.jdbcli.exception.JdbcliException;
89
import io.github.denyshorman.jdbcli.profile.ProfileLoader;
910
import io.github.denyshorman.jdbcli.profile.ProfileWriter;
1011
import io.github.denyshorman.jdbcli.util.FileSystemUtil;
1112
import io.github.denyshorman.jdbcli.util.JsonUtil;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1215
import picocli.CommandLine.Command;
1316
import picocli.CommandLine.Option;
1417

1518
import java.util.Map;
1619

17-
import io.github.denyshorman.jdbcli.driver.DriverInstaller;
18-
19-
import org.slf4j.Logger;
20-
import org.slf4j.LoggerFactory;
21-
2220
@Command(
2321
name = "profile",
2422
description = {
@@ -103,10 +101,10 @@ public void list() {
103101
public void show(@Option(names = "--profile", required = true, paramLabel = "<name>", description = "Profile name to display") String name) {
104102
var p = ProfileLoader.load(name);
105103

106-
if (p != null) {
107-
System.out.println(JsonUtil.MAPPER.writeValueAsString(p));
108-
} else {
109-
LOGGER.error("Profile not found: {}", name);
104+
if (p == null) {
105+
throw new JdbcliException("Profile not found: " + name);
110106
}
107+
108+
System.out.println(JsonUtil.MAPPER.writeValueAsString(p));
111109
}
112110
}

src/main/java/io/github/denyshorman/jdbcli/util/FileSystemUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
public class FileSystemUtil {
66
public static Path getJdbcliHome() {
7+
var override = System.getProperty("jdbcli.home");
8+
9+
if (override != null) {
10+
return Path.of(override);
11+
}
12+
713
return Path.of(System.getProperty("user.home"), ".jdbcli");
814
}
915
}

0 commit comments

Comments
 (0)