@@ -3,23 +3,40 @@ package processing.app.api
33import com.github.ajalt.clikt.command.SuspendingCliktCommand
44import com.github.ajalt.clikt.core.Context
55import com.github.ajalt.clikt.core.subcommands
6- import processing.app.Base
6+ import kotlinx.serialization.encodeToString
7+ import kotlinx.serialization.json.Json
8+ import processing.app.Platform
9+ import processing.app.Preferences
710import processing.app.api.Sketch.Companion.getSketches
11+ import java.io.File
812
913class Sketchbook : SuspendingCliktCommand () {
14+
15+
1016 override fun help (context : Context ) = " Manage the sketchbook"
1117 override suspend fun run () {
1218 System .setProperty(" java.awt.headless" , " true" )
1319 }
1420 init {
1521 subcommands(SketchbookList ())
1622 }
23+
24+
1725 class SketchbookList : SuspendingCliktCommand (" list" ) {
26+ val serializer = Json {
27+ prettyPrint = true
28+ }
29+
1830 override fun help (context : Context ) = " List all sketches"
1931 override suspend fun run () {
20- val sketchbookFolder = Base .getSketchbookFolder()
32+ Platform .init ()
33+ // TODO: Allow the user to change the sketchbook location
34+ // TODO: Currently blocked since `Base.getSketchbookFolder()` is not available in headless mode
35+ val sketchbookFolder = Platform .getDefaultSketchbookFolder()
2136
22- val sketches = getSketches(sketchbookFolder)
37+ val sketches = getSketches(sketchbookFolder.resolve(" sketchbook" ))
38+ val json = serializer.encodeToString(listOf (sketches))
39+ println (json)
2340 }
2441 }
2542}
0 commit comments