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.arguments.argument
8
+ import com.github.ajalt.clikt.parameters.arguments.help
9
+ import com.github.ajalt.clikt.parameters.arguments.multiple
10
+ import com.github.ajalt.clikt.parameters.options.flag
11
+ import com.github.ajalt.clikt.parameters.options.help
12
+ import com.github.ajalt.clikt.parameters.options.option
13
+ import processing.app.ui.Start
14
+
15
+ class Processing : SuspendingCliktCommand (" processing" ){
16
+ val version by option(" -v" ," --version" )
17
+ .flag()
18
+ .help(" Print version information" )
19
+
20
+ val sketches by argument()
21
+ .multiple(default = emptyList())
22
+ .help(" Sketches to open" )
23
+
24
+ override fun help (context : Context ) = " Start the Processing IDE"
25
+ override val invokeWithoutSubcommand = true
26
+ override suspend fun run () {
27
+ if (version){
28
+ println (" processing-${Base .getVersionName()} -${Base .getRevision()} " )
29
+ return
30
+ }
31
+
32
+ val subcommand = currentContext.invokedSubcommand
33
+ if (subcommand == null ) {
34
+ Start .main(sketches.toTypedArray())
35
+ }
36
+ }
37
+ }
38
+
39
+ suspend fun main (args : Array <String >){
40
+ Processing ()
41
+ .subcommands(
42
+ LSP (),
43
+ LegacyCLI (args)
44
+ )
45
+ .main(args)
46
+ }
47
+
48
+ class LSP : SuspendingCliktCommand (" lsp" ){
49
+ override fun help (context : Context ) = " Start the Processing Language Server"
50
+ override suspend fun run (){
51
+ try {
52
+ // Indirect invocation since app does not depend on java mode
53
+ Class .forName(" processing.mode.java.lsp.PdeLanguageServer" )
54
+ .getMethod(" main" , Array <String >::class .java)
55
+ .invoke(null , * arrayOf<Any >(emptyList<String >()))
56
+ } catch (e: Exception ) {
57
+ throw InternalError (" Failed to invoke main method" , e)
58
+ }
59
+ }
60
+ }
61
+
62
+ class LegacyCLI (val args : Array <String >): SuspendingCliktCommand( " cli" ){
63
+ override fun help (context : Context ) = " Legacy processing-java command line interface"
64
+
65
+ val help by option(" --help" ).flag()
66
+ val build by option(" --build" ).flag()
67
+ val run by option(" --run" ).flag()
68
+ val present by option(" --present" ).flag()
69
+ val sketch: String? by option(" --sketch" )
70
+ val force by option(" --force" ).flag()
71
+ val output: String? by option(" --output" )
72
+ val export by option(" --export" ).flag()
73
+ val noJava by option(" --no-java" ).flag()
74
+ val variant: String? by option(" --variant" )
75
+
76
+ override suspend fun run (){
77
+ val cliArgs = args.filter { it != " cli" }
78
+ try {
79
+ if (build){
80
+ System .setProperty(" java.awt.headless" , " true" )
81
+ }
82
+ // Indirect invocation since app does not depend on java mode
83
+ Class .forName(" processing.mode.java.Commander" )
84
+ .getMethod(" main" , Array <String >::class .java)
85
+ .invoke(null , * arrayOf<Any >(cliArgs.toTypedArray()))
86
+ } catch (e: Exception ) {
87
+ throw InternalError (" Failed to invoke main method" , e)
88
+ }
89
+ }
90
+ }
0 commit comments