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+ }
0 commit comments