Skip to content

Commit 51c9734

Browse files
committed
Refined Command Line Structure
1 parent fd571d1 commit 51c9734

File tree

4 files changed

+63
-44
lines changed

4 files changed

+63
-44
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ dependencies {
123123
testImplementation(libs.junitJupiter)
124124
testImplementation(libs.junitJupiterParams)
125125

126-
implementation("com.github.ajalt.clikt:clikt:5.0.2")
126+
implementation(libs.clikt)
127127
}
128128

129129
tasks.test {

app/src/processing/app/Processing.kt

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,49 @@ import com.github.ajalt.clikt.command.SuspendingCliktCommand
44
import com.github.ajalt.clikt.command.main
55
import com.github.ajalt.clikt.core.Context
66
import com.github.ajalt.clikt.core.subcommands
7+
import com.github.ajalt.clikt.parameters.arguments.argument
8+
import com.github.ajalt.clikt.parameters.arguments.multiple
79
import com.github.ajalt.clikt.parameters.options.flag
810
import com.github.ajalt.clikt.parameters.options.option
911
import processing.app.ui.Start
1012

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"){
13+
class Processing: SuspendingCliktCommand("processing"){
14+
val sketches by argument().multiple(default = emptyList())
15+
16+
override fun help(context: Context) = "Start the Processing IDE"
17+
override val invokeWithoutSubcommand = true
1618
override suspend fun run() {
17-
if(currentContext.invokedSubcommand == null){
18-
Start.main(args)
19+
val subcommand = currentContext.invokedSubcommand
20+
if (subcommand == null) {
21+
Start.main(sketches.toTypedArray())
1922
}
2023
}
2124
}
2225

23-
suspend fun main(args: Array<String>) = Processing(args)
24-
.subcommands(
25-
LSP(args),
26-
LegacyCLI(args)
27-
)
28-
.main(args)
29-
26+
suspend fun main(args: Array<String>){
27+
Processing()
28+
.subcommands(
29+
LSP(),
30+
LegacyCLI(args)
31+
)
32+
.main(args)
33+
}
3034

31-
class LSP(val args: Array<String>): SuspendingCliktCommand("lsp"){
35+
class LSP: SuspendingCliktCommand("lsp"){
3236
override fun help(context: Context) = "Start the Processing Language Server"
3337
override suspend fun run(){
3438
try {
3539
// Indirect invocation since app does not depend on java mode
3640
Class.forName("processing.mode.java.lsp.PdeLanguageServer")
3741
.getMethod("main", Array<String>::class.java)
38-
.invoke(null, *arrayOf<Any>(args))
42+
.invoke(null, *arrayOf<Any>(emptyList<String>()))
3943
} catch (e: Exception) {
4044
throw InternalError("Failed to invoke main method", e)
4145
}
4246
}
4347
}
4448

45-
class LegacyCLI(val args: Array<String>): SuspendingCliktCommand(name = "cli"){
49+
class LegacyCLI(val args: Array<String>): SuspendingCliktCommand( "cli"){
4650
override fun help(context: Context) = "Legacy processing-java command line interface"
4751

4852
val help by option("--help").flag()
@@ -57,12 +61,15 @@ class LegacyCLI(val args: Array<String>): SuspendingCliktCommand(name = "cli"){
5761
val variant: String? by option("--variant")
5862

5963
override suspend fun run(){
60-
val cliArgs = args.filter { it != "cli" }.toTypedArray()
64+
val cliArgs = args.filter { it != "cli" }
6165
try {
66+
if(build){
67+
System.setProperty("java.awt.headless", "true")
68+
}
6269
// Indirect invocation since app does not depend on java mode
6370
Class.forName("processing.mode.java.Commander")
6471
.getMethod("main", Array<String>::class.java)
65-
.invoke(null, *arrayOf<Any>(cliArgs))
72+
.invoke(null, *arrayOf<Any>(cliArgs.toTypedArray()))
6673
} catch (e: Exception) {
6774
throw InternalError("Failed to invoke main method", e)
6875
}

app/src/processing/app/tools/InstallCommander.java

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,41 @@ public void run() {
8686
PrintWriter writer = PApplet.createWriter(file);
8787
writer.print("#!/bin/sh\n\n");
8888

89-
writer.print("# Prevents processing-java from stealing focus, see:\n" +
90-
"# https://github.com/processing/processing/issues/3996.\n" +
91-
"OPTION_FOR_HEADLESS_RUN=\"\"\n" +
92-
"for ARG in \"$@\"\n" +
93-
"do\n" +
94-
" if [ \"$ARG\" = \"--build\" ]; then\n" +
95-
" OPTION_FOR_HEADLESS_RUN=\"-Djava.awt.headless=true\"\n" +
96-
" fi\n" +
97-
"done\n\n");
98-
99-
String javaRoot = Platform.getContentFile(".").getCanonicalPath();
100-
101-
StringList jarList = new StringList();
102-
addJarList(jarList, new File(javaRoot));
103-
addJarList(jarList, new File(javaRoot, "core/library"));
104-
addJarList(jarList, new File(javaRoot, "modes/java/mode"));
105-
String classPath = jarList.join(":").replaceAll(javaRoot + "\\/?", "");
106-
107-
writer.println("cd \"" + javaRoot + "\" && " +
108-
Platform.getJavaPath().replaceAll(" ", "\\\\ ") +
109-
" -Djna.nosys=true" +
110-
" $OPTION_FOR_HEADLESS_RUN" +
111-
" -cp \"" + classPath + "\"" +
112-
" processing.mode.java.Commander \"$@\"");
89+
var resourcesDir = System.getProperty("compose.application.resources.dir");
90+
if(resourcesDir != null) {
91+
// Gradle based distributable
92+
var appBinary = (resourcesDir
93+
.split("\\.app")[0] + ".app/Contents/MacOS/Processing")
94+
.replaceAll(" ", "\\\\ ");
95+
writer.print(appBinary + " cli $@");
96+
97+
} else {
98+
// Ant based distributable
99+
writer.print("# Prevents processing-java from stealing focus, see:\n" +
100+
"# https://github.com/processing/processing/issues/3996.\n" +
101+
"OPTION_FOR_HEADLESS_RUN=\"\"\n" +
102+
"for ARG in \"$@\"\n" +
103+
"do\n" +
104+
" if [ \"$ARG\" = \"--build\" ]; then\n" +
105+
" OPTION_FOR_HEADLESS_RUN=\"-Djava.awt.headless=true\"\n" +
106+
" fi\n" +
107+
"done\n\n");
108+
109+
String javaRoot = Platform.getContentFile(".").getCanonicalPath();
110+
111+
StringList jarList = new StringList();
112+
addJarList(jarList, new File(javaRoot));
113+
addJarList(jarList, new File(javaRoot, "core/library"));
114+
addJarList(jarList, new File(javaRoot, "modes/java/mode"));
115+
String classPath = jarList.join(":").replaceAll(javaRoot + "\\/?", "");
116+
117+
writer.println("cd \"" + javaRoot + "\" && " +
118+
Platform.getJavaPath().replaceAll(" ", "\\\\ ") +
119+
" -Djna.nosys=true" +
120+
" $OPTION_FOR_HEADLESS_RUN" +
121+
" -cp \"" + classPath + "\"" +
122+
" processing.mode.java.Commander \"$@\"");
123+
}
113124
writer.flush();
114125
writer.close();
115126
file.setExecutable(true);

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ lsp4j = { module = "org.eclipse.lsp4j:org.eclipse.lsp4j", version = "0.22.0" }
2727
jsoup = { module = "org.jsoup:jsoup", version = "1.17.2" }
2828
markdown = { module = "com.mikepenz:multiplatform-markdown-renderer-m2", version = "0.31.0" }
2929
markdownJVM = { module = "com.mikepenz:multiplatform-markdown-renderer-jvm", version = "0.31.0" }
30+
clikt = { module = "com.github.ajalt.clikt:clikt", version = "5.0.2" }
3031

3132
[plugins]
3233
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }

0 commit comments

Comments
 (0)