@@ -79,7 +79,7 @@ class ElideCliService(private val project: Project, private val serviceScope: Co
7979 */
8080 fun launch (
8181 elideBinary : Path ,
82- projectPath : String ,
82+ workdir : String? = null ,
8383 scope : CoroutineScope ,
8484 buildCommand : MutableList <String >.() -> Unit
8585 ): ElideProcess {
@@ -89,7 +89,7 @@ class ElideCliService(private val project: Project, private val serviceScope: Co
8989 }
9090
9191 val process = ProcessBuilder (command)
92- .directory(File (projectPath))
92+ .also { if (workdir != null ) it. directory(File (workdir)) }
9393 .start()
9494
9595 return ElideProcess (process, scope, scope.async { process.awaitExit() })
@@ -98,19 +98,52 @@ class ElideCliService(private val project: Project, private val serviceScope: Co
9898 }
9999
100100 /* *
101- * Launch the Elide CLI binary as a subprocess and wrap it in [ElideProcess] for easy handling. The settings of the
102- * linked project at [projectPath] are used to select an Elide distribution to be invoked .
101+ * A bridge used to call an Elide Command Line distribution at a specific path. Use the command methods to interface
102+ * with the CLI without blocking .
103103 */
104- private fun launchElide (projectPath : String , buildCommand : MutableList <String >.() -> Unit ): ElideProcess {
105- val elideHome = ElideDistributionResolver .getElideHome(project, projectPath)
106- val elideBin = elideHome.resolve(Constants .ELIDE_BINARY )
104+ class ElideCommandLine private constructor(
105+ private val elideHome : Path ,
106+ private val scope : CoroutineScope ,
107+ ) {
108+ /* * Invoke the Elide CLI with the `--version` option in a background context and return its output. */
109+ suspend fun version (workdir : String? = null): String = withContext(Dispatchers .IO ) {
110+ val elide = launchElide(elideHome, workdir, buildCommand = { add(" --version" ) })
111+ elide.readStdOut()
112+ }
107113
108- return ElideProcess .launch(elideBin, projectPath, serviceScope, buildCommand)
114+ /* *
115+ * Launch the Elide CLI binary as a subprocess and wrap it in [ElideProcess] for easy handling. The settings of the
116+ * linked project at [workdir] are used to select an Elide distribution to be invoked.
117+ */
118+ private fun launchElide (
119+ elideHome : Path ,
120+ workdir : String? = null,
121+ buildCommand : MutableList <String >.() -> Unit
122+ ): ElideProcess {
123+ val elideBin = elideHome.resolve(Constants .ELIDE_BINARY )
124+ return ElideProcess .launch(elideBin, workdir, scope, buildCommand)
125+ }
126+
127+ companion object {
128+ fun at (elideHome : Path , scope : CoroutineScope ): ElideCommandLine {
129+ return ElideCommandLine (elideHome, scope)
130+ }
131+ }
132+ }
133+
134+ /* * Returns a configured [ElideCommandLine] at the given [elideHome]. */
135+ fun at (elideHome : Path ): ElideCommandLine {
136+ return ElideCommandLine .at(elideHome, serviceScope)
109137 }
110138
111- /* * Invoke the Elide CLI with the `--version` option in a background context and return its output. */
112- fun version (projectPath : String ): Deferred <String > = serviceScope.async {
113- val elide = launchElide(projectPath, buildCommand = { add(" --version" ) })
114- elide.readStdOut()
139+ /* * Resolves an [ElideCommandLine] for the linked project at [externalProjectPath]. */
140+ fun resolve (externalProjectPath : String ): ElideCommandLine {
141+ return ElideCommandLine .at(ElideDistributionResolver .getElideHome(project, externalProjectPath), serviceScope)
142+ }
143+
144+ companion object {
145+ fun getInstance (project : Project ): ElideCliService {
146+ return project.getService(ElideCliService ::class .java)
147+ }
115148 }
116149}
0 commit comments