Skip to content

Commit fd571d1

Browse files
committed
Initial Command Line structure
1 parent ecd219b commit fd571d1

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

app/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ sourceSets{
4747

4848
compose.desktop {
4949
application {
50-
mainClass = "processing.app.ui.Start"
50+
mainClass = "processing.app.ProcessingKt"
5151

5252
jvmArgs(*listOf(
5353
Pair("processing.version", rootProject.version),
@@ -97,6 +97,7 @@ compose.desktop {
9797

9898
dependencies {
9999
implementation(project(":core"))
100+
runtimeOnly(project(":java"))
100101

101102
implementation(libs.flatlaf)
102103

@@ -121,6 +122,8 @@ dependencies {
121122
testImplementation(libs.mockitoKotlin)
122123
testImplementation(libs.junitJupiter)
123124
testImplementation(libs.junitJupiterParams)
125+
126+
implementation("com.github.ajalt.clikt:clikt:5.0.2")
124127
}
125128

126129
tasks.test {

app/src/processing/app/Processing.kt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package processing.app
2+
3+
import com.github.ajalt.clikt.command.SuspendingCliktCommand
4+
import com.github.ajalt.clikt.command.main
5+
import com.github.ajalt.clikt.core.Context
6+
import com.github.ajalt.clikt.core.subcommands
7+
import com.github.ajalt.clikt.parameters.options.flag
8+
import com.github.ajalt.clikt.parameters.options.option
9+
import processing.app.ui.Start
10+
11+
// TODO: Allow Start to run on no args
12+
// TODO: Modify InstallCommander to use the new structure
13+
// TODO: Move dependency to gradle toml
14+
// TODO: Add the options/arguments for Base arguments
15+
class Processing(val args: Array<String>): SuspendingCliktCommand(name = "Processing"){
16+
override suspend fun run() {
17+
if(currentContext.invokedSubcommand == null){
18+
Start.main(args)
19+
}
20+
}
21+
}
22+
23+
suspend fun main(args: Array<String>) = Processing(args)
24+
.subcommands(
25+
LSP(args),
26+
LegacyCLI(args)
27+
)
28+
.main(args)
29+
30+
31+
class LSP(val args: Array<String>): SuspendingCliktCommand("lsp"){
32+
override fun help(context: Context) = "Start the Processing Language Server"
33+
override suspend fun run(){
34+
try {
35+
// Indirect invocation since app does not depend on java mode
36+
Class.forName("processing.mode.java.lsp.PdeLanguageServer")
37+
.getMethod("main", Array<String>::class.java)
38+
.invoke(null, *arrayOf<Any>(args))
39+
} catch (e: Exception) {
40+
throw InternalError("Failed to invoke main method", e)
41+
}
42+
}
43+
}
44+
45+
class LegacyCLI(val args: Array<String>): SuspendingCliktCommand(name = "cli"){
46+
override fun help(context: Context) = "Legacy processing-java command line interface"
47+
48+
val help by option("--help").flag()
49+
val build by option("--build").flag()
50+
val run by option("--run").flag()
51+
val present by option("--present").flag()
52+
val sketch: String? by option("--sketch")
53+
val force by option("--force").flag()
54+
val output: String? by option("--output")
55+
val export by option("--export").flag()
56+
val noJava by option("--no-java").flag()
57+
val variant: String? by option("--variant")
58+
59+
override suspend fun run(){
60+
val cliArgs = args.filter { it != "cli" }.toTypedArray()
61+
try {
62+
// Indirect invocation since app does not depend on java mode
63+
Class.forName("processing.mode.java.Commander")
64+
.getMethod("main", Array<String>::class.java)
65+
.invoke(null, *arrayOf<Any>(cliArgs))
66+
} catch (e: Exception) {
67+
throw InternalError("Failed to invoke main method", e)
68+
}
69+
}
70+
}

core/examples/src/main/java/Basic.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import processing.core.PApplet;
22

3+
import java.io.IOException;
4+
35
public class Basic extends PApplet {
46
public void settings(){
57
size(500, 500);
8+
9+
try {
10+
Runtime.getRuntime().exec("echo Hello World");
11+
} catch (IOException e) {
12+
throw new RuntimeException(e);
13+
}
614
}
715

816
public void draw(){
9-
ellipse(width / 2f, height / 2f, 125f, 125f);
17+
background(255);
18+
fill(0);
19+
ellipse(mouseX, mouseY, 125f, 125f);
20+
println(frameRate);
21+
22+
1023
}
1124

1225

java/src/processing/mode/java/lsp/PdeLanguageServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.eclipse.lsp4j.services.LanguageClient;
2222

2323

24-
class PdeLanguageServer implements LanguageServer, LanguageClientAware {
24+
public class PdeLanguageServer implements LanguageServer, LanguageClientAware {
2525
Map<File, PdeAdapter> adapters = new HashMap<>();
2626
LanguageClient client = null;
2727
PdeTextDocumentService textDocumentService = new PdeTextDocumentService(this);

0 commit comments

Comments
 (0)