Skip to content

Commit

Permalink
refactor AptosCommandLine
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Nov 12, 2024
1 parent 7519a89 commit 5be42ea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
37 changes: 10 additions & 27 deletions src/main/kotlin/org/move/cli/runConfigurations/AptosCommandLine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,16 @@ import com.intellij.execution.configuration.EnvironmentVariablesData
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.configurations.PtyCommandLine
import com.intellij.util.execution.ParametersListUtil
import org.move.cli.tools.MvCommandLine
import java.nio.file.Path

data class AptosCommandLine(
class AptosCommandLine(
val subCommand: String?,
val arguments: List<String> = emptyList(),
val workingDirectory: Path? = null,
val environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT
) {
val commandLineString: String
get() = ParametersListUtil.join(subCommand?.split(" ").orEmpty() + arguments)

fun toGeneralCommandLine(cliExePath: Path, emulateTerminal: Boolean = false): GeneralCommandLine {
var commandLine = GeneralCommandLine()
.withExePath(cliExePath.toString())
// subcommand can be null
.withParameters(subCommand?.split(" ").orEmpty())
.withParameters(this.arguments)
.withWorkingDirectory(this.workingDirectory)
.withCharset(Charsets.UTF_8)
// disables default coloring for stderr
.withRedirectErrorStream(true)
this.environmentVariables.configureCommandLine(commandLine, true)

if (emulateTerminal) {
commandLine = PtyCommandLine(commandLine)
}

return commandLine
}
}
arguments: List<String> = emptyList(),
workingDirectory: Path? = null,
environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT
): MvCommandLine(
subCommand?.split(" ").orEmpty() + arguments,
workingDirectory,
environmentVariables
)
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ abstract class CommandConfigurationBase(
workingDirectory,
environmentVariables
)
return CleanConfiguration.Ok(aptosPath, commandLine)
return CleanConfiguration.
Ok(aptosPath, commandLine)
}

protected fun showTestToolWindow(commandLine: AptosCommandLine): Boolean =
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/org/move/cli/tools/MvCommandLine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.move.cli.tools

import com.intellij.execution.configuration.EnvironmentVariablesData
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.configurations.PtyCommandLine
import com.intellij.util.execution.ParametersListUtil
import java.nio.file.Path

open class MvCommandLine(
val arguments: List<String> = emptyList(),
val workingDirectory: Path? = null,
val environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT
) {
val commandLineString: String get() = ParametersListUtil.join(arguments)

fun toGeneralCommandLine(cliExePath: Path, emulateTerminal: Boolean = false): GeneralCommandLine {
var commandLine = GeneralCommandLine()
.withExePath(cliExePath.toString())
.withParameters(this.arguments)
.withWorkingDirectory(this.workingDirectory)
.withCharset(Charsets.UTF_8)
// disables default coloring for stderr
.withRedirectErrorStream(true)
this.environmentVariables.configureCommandLine(commandLine, true)
if (emulateTerminal) {
commandLine = PtyCommandLine(commandLine)
}
return commandLine
}
}

0 comments on commit 5be42ea

Please sign in to comment.