@@ -4,45 +4,49 @@ import com.github.ajalt.clikt.command.SuspendingCliktCommand
44import com.github.ajalt.clikt.command.main
55import com.github.ajalt.clikt.core.Context
66import com.github.ajalt.clikt.core.subcommands
7+ import com.github.ajalt.clikt.parameters.arguments.argument
8+ import com.github.ajalt.clikt.parameters.arguments.multiple
79import com.github.ajalt.clikt.parameters.options.flag
810import com.github.ajalt.clikt.parameters.options.option
911import 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 }
0 commit comments