Skip to content

Commit 1b2d23c

Browse files
devhawkchuck-dbosCopilot
authored
DBOS CLI (#201)
Note, `init` command will come in a later PR --------- Co-authored-by: chuck-dbos <134347445+chuck-dbos@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 004cf5c commit 1b2d23c

16 files changed

Lines changed: 1237 additions & 26 deletions

File tree

transact-cli/README.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# DBOS CLI
2+
3+
The DBOS CLI is a command-line interface for managing DBOS workflows.
4+
5+
## Installation
6+
7+
DBOS CLI is distributed as a JAR with dependencies (also known as a fat or uber JAR).
8+
It is run from the command line with the `-jar` option of the [`java` command](https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html).
9+
10+
```shell
11+
$ java -jar dbos.jar --version
12+
dbos v0.7.0
13+
```
14+
15+
## Configuration
16+
17+
### Database Connection Configuration
18+
19+
Many of the DBOS CLI commands require a DBOS system database connection to operate.
20+
The DBOS system database connection is specified via a JDBC URL plus a username and password.
21+
These values can be specified on the command line or via environment variables.
22+
23+
* System Database JDBC URL
24+
* `--db-url` / `-D` flag
25+
* `DBOS_SYSTEM_JDBC_URL` environment variable
26+
* System Database user
27+
* `--db-user` / `-U` flag
28+
* `PGUSER` environment variable
29+
* System Database password
30+
* `--db-password` / `-P` flag
31+
* `PGPASSWORD` environment variable
32+
33+
Example:
34+
```bash
35+
# Using command-line flag (highest priority)
36+
java -jar dbos.jar migrate --db-url jdbc:postgresql://localhost/mydb -U user -P password
37+
38+
# Using environment variable (lowest priority)
39+
export DBOS_SYSTEM_JDBC_URL=jdbc:postgresql://localhost/mydb
40+
export PGUSER=user
41+
export PGPASSWORD=password
42+
java -jar dbos.jar migrate
43+
```
44+
45+
### `dbos migrate`
46+
Create DBOS system tables in your database. This command runs the migration commands specified in the `database.migrate` section of your config file.
47+
48+
**Options:**
49+
- `-r, --app-role <role>` - The role with which you will run your DBOS application
50+
51+
**Usage:**
52+
```bash
53+
java -jar dbos.jar migrate
54+
java -jar dbos.jar migrate --app-role myapp_role
55+
```
56+
57+
### `dbos reset`
58+
Reset the DBOS system database, deleting metadata about past workflows and steps. _This is a permanent, destructive action!_
59+
60+
**Options:**
61+
- `-y, --yes` - Skip confirmation prompt
62+
63+
**Usage:**
64+
```bash
65+
java -jar dbos.jar reset
66+
java -jar dbos.jar reset --yes # Skip confirmation
67+
```
68+
69+
### `dbos postgres`
70+
Manage a local PostgreSQL database with Docker for development.
71+
72+
#### `dbos postgres start`
73+
Start a local Postgres database container with pgvector extension.
74+
75+
**Options:**
76+
- `-c, --container-name` - Docker container name, defaults to dbos-db
77+
- `-i, --image-name` - Docker image name, defaults to pgvector/pgvector:pg16
78+
79+
**Usage:**
80+
```bash
81+
java -jar dbos.jar postgres start
82+
```
83+
84+
Creates a PostgreSQL container with:
85+
- Container name: `dbos-db` (unless overridden by `--container-name`)
86+
- Port: 5432
87+
- Default database: `dbos`
88+
- Default user: `postgres`
89+
- Default password: `dbos`
90+
91+
#### `dbos postgres stop`
92+
Stop the local Postgres database container.
93+
94+
**Usage:**
95+
```bash
96+
java -jar dbos.jar postgres stop
97+
```
98+
**Options:**
99+
- `-c, --container-name` - Docker container name, defaults to dbos-db
100+
101+
### `dbos workflow`
102+
Manage DBOS workflows.
103+
104+
#### `dbos workflow list`
105+
List workflows for your application.
106+
107+
**Options:**
108+
- `-l, --limit <number>` - Limit the results returned (default: 10)
109+
- `-o, --offset <number>` - Offset for pagination
110+
- `-S, --status <status>` - Filter by status (PENDING, SUCCESS, ERROR, ENQUEUED, CANCELLED, or MAX_RECOVERY_ATTEMPTS_EXCEEDED)
111+
- `-n, --name <name>` - Retrieve workflows with this name
112+
- `-v, --application-version <version>` - Retrieve workflows with this application version
113+
- `-s, --start-time <timestamp>` - Retrieve workflows starting after this timestamp (ISO 8601)
114+
- `-e, --end-time <timestamp>` - Retrieve workflows starting before this timestamp (ISO 8601)
115+
- `-q, --queue <queue>` - Retrieve workflows on this queue
116+
- `-Q, --queues-only` - Retrieve only queued workflows
117+
- `-d, --sort-desc` - Sort the results in descending order (older first)
118+
119+
**Usage:**
120+
```bash
121+
java -jar dbos.jar workflow list
122+
java -jar dbos.jar workflow list --limit 50 --status SUCCESS
123+
java -jar dbos.jar workflow list --name "ProcessOrder"
124+
```
125+
126+
#### `dbos workflow get [workflow-id]`
127+
Retrieve the status of a specific workflow.
128+
129+
**Usage:**
130+
```bash
131+
java -jar dbos.jar workflow get abc123def456
132+
```
133+
134+
Returns detailed information about the workflow including its status, start time, end time, and other metadata.
135+
136+
#### `dbos workflow steps [workflow-id]`
137+
List the steps of a workflow.
138+
139+
**Usage:**
140+
```bash
141+
java -jar dbos.jar workflow steps abc123def456
142+
```
143+
144+
Shows all the steps executed within a workflow, their status, and execution details.
145+
146+
#### `dbos workflow cancel [workflow-id]`
147+
Cancel a workflow so it is no longer automatically retried or restarted.
148+
149+
**Usage:**
150+
```bash
151+
java -jar dbos.jar workflow cancel abc123def456
152+
```
153+
154+
#### `dbos workflow resume [workflow-id]`
155+
Resume a workflow that has been cancelled.
156+
157+
**Usage:**
158+
```bash
159+
java -jar dbos.jar workflow resume abc123def456
160+
```
161+
162+
#### `dbos workflow fork [workflow-id]`
163+
Fork a workflow from the beginning or from a specific step.
164+
165+
**Options:**
166+
- `-s, --step <number>` - Restart from this step (default: 1)
167+
- `-f, --forked-workflow-id <id>` - Custom workflow ID for the forked workflow
168+
- `-a, --application-version <version>` - Application version for the forked workflow
169+
170+
**Usage:**
171+
```bash
172+
java -jar dbos.jar workflow fork abc123def456
173+
java -jar dbos.jar workflow fork abc123def456 --step 3
174+
java -jar dbos.jar workflow fork abc123def456 --forked-workflow-id custom-id-123
175+
```
176+
177+
### `dbos version`
178+
Show the version and exit.
179+
180+
**Usage:**
181+
```bash
182+
java -jar dbos.jar --version
183+
```
184+
185+
## License
186+
187+
See the main project [LICENSE](https://github.com/dbos-inc/dbos-transact-java/blob/main/LICENSE) file for details.

transact-cli/build.gradle.kts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
application
3+
id("com.gradleup.shadow") version "9.2.2"
34
}
45

56
application {
@@ -8,4 +9,43 @@ application {
89

910
dependencies {
1011
implementation(project(":transact"))
12+
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.0") // json
13+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.0")
14+
implementation("info.picocli:picocli:4.7.7")
15+
runtimeOnly("org.slf4j:slf4j-simple:2.0.13")
16+
17+
testImplementation(platform("org.junit:junit-bom:5.12.1"))
18+
testImplementation("org.junit.jupiter:junit-jupiter")
19+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
20+
}
21+
22+
tasks.test {
23+
useJUnitPlatform()
24+
testLogging {
25+
events("passed", "skipped", "failed")
26+
showStandardStreams = true
27+
28+
afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
29+
if (desc.parent == null) {
30+
println("\nTest Results:")
31+
println(" Tests run: ${result.testCount}")
32+
println(" Passed: ${result.successfulTestCount}")
33+
println(" Failed: ${result.failedTestCount}")
34+
println(" Skipped: ${result.skippedTestCount}")
35+
}
36+
}))
37+
}
38+
}
39+
40+
tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
41+
archiveBaseName.set("dbos")
42+
archiveVersion.set("")
43+
archiveClassifier.set("")
44+
}
45+
46+
tasks.withType<JavaCompile> {
47+
options.compilerArgs.add("-Xlint:unchecked") // warn about unchecked operations
48+
options.compilerArgs.add("-Xlint:deprecation") // warn about deprecated APIs
49+
options.compilerArgs.add("-Xlint:rawtypes") // warn about raw types
50+
options.compilerArgs.add("-Werror") // treat all warnings as errors
1151
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package dev.dbos.transact.cli;
2+
3+
import dev.dbos.transact.DBOS;
4+
5+
import java.util.Objects;
6+
7+
import picocli.CommandLine;
8+
import picocli.CommandLine.Command;
9+
import picocli.CommandLine.IVersionProvider;
10+
11+
@Command(
12+
name = "dbos",
13+
description = "DBOS CLI is a command-line interface for managing DBOS workflows",
14+
mixinStandardHelpOptions = true,
15+
subcommands = {
16+
MigrateCommand.class,
17+
PostgresCommand.class,
18+
ResetCommand.class,
19+
WorkflowCommand.class
20+
},
21+
versionProvider = DBOSCommand.class)
22+
public class DBOSCommand implements Runnable, IVersionProvider {
23+
24+
@Override
25+
public void run() {
26+
CommandLine cmd = new CommandLine(this);
27+
cmd.usage(System.out);
28+
}
29+
30+
@Override
31+
public String[] getVersion() throws Exception {
32+
var pkg = DBOS.class.getPackage();
33+
var ver = pkg == null ? null : "v%s".formatted(pkg.getImplementationVersion());
34+
return new String[] {
35+
"${COMMAND-FULL-NAME} " + Objects.requireNonNullElse(ver, "<unknown version>")
36+
};
37+
}
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package dev.dbos.transact.cli;
2+
3+
import dev.dbos.transact.DBOSClient;
4+
5+
import picocli.CommandLine.Option;
6+
7+
public class DatabaseOptions {
8+
@Option(
9+
names = {"-D", "--db-url"},
10+
defaultValue = "${DBOS_SYSTEM_JDBC_URL}",
11+
description = "Your DBOS system database URL [default: DBOS_SYSTEM_JDBC_URL env var]")
12+
private String url;
13+
14+
@Option(
15+
names = {"-U", "--db-user"},
16+
defaultValue = "${PGUSER}",
17+
description = "user name for your DBOS system database [default: PGUSER env var]")
18+
private String user;
19+
20+
@Option(
21+
names = {"-P", "--db-password"},
22+
defaultValue = "${PGPASSWORD}",
23+
description = "password for your DBOS system database [default: PGPASSWORD env var]",
24+
arity = "0..1",
25+
interactive = true)
26+
private String password;
27+
28+
public String url() {
29+
return this.url;
30+
}
31+
32+
public String user() {
33+
return this.user;
34+
}
35+
36+
public String password() {
37+
return this.password;
38+
}
39+
40+
public DBOSClient createClient() {
41+
return new DBOSClient(url(), user(), password());
42+
}
43+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package dev.dbos.transact.cli;
22

3+
import picocli.CommandLine;
4+
35
public class Main {
46
public static void main(String[] args) {
5-
System.out.println("Hello World");
7+
var cmd = new CommandLine(new DBOSCommand());
8+
var exitCode = cmd.execute(args);
9+
System.exit(exitCode);
610
}
711
}

0 commit comments

Comments
 (0)