All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.KommandExec.kt Maven / Gradle / Ivy

There is a newer version: 0.0.87
Show newest version
package pl.mareklangiewicz.kommand

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import pl.mareklangiewicz.bad.*


// TODO_someday: CLI as context parameter
//  for now convention is: first parameter "cli: CLI", because it's the same as kgroundxio:WithCLI interface
/**
 * The ax Awaits/eXecutes the kommand. And it's dangerous :)
 * It has to be explicitly called for every kommand in the "script" so has to be short "keyword" to memorize.
 * TODO_someday: how to colorize it (can I somehow use @DslMarker ?)
 */
suspend fun Kommand.ax(
  vararg useNamedArgs: Unit,
  dir: String? = null,
  inContent: String? = null,
  inLineS: Flow? = inContent?.lineSequence()?.asFlow(),
  inFile: String? = null,
  outFile: String? = null,
): List = coroutineScope {
  val cli = implictx()
  req(cli.isRedirectFileSupported || (inFile == null && outFile == null)) { "redirect file not supported here" }
  req(inLineS == null || inFile == null) { "Either inLineS or inFile or none, but not both" }
  cli.lx(this@ax, dir = dir, inFile = inFile, outFile = outFile)
    .awaitResult(inLineS = inLineS)
    .unwrap()
}







© 2015 - 2024 Weber Informatics LLC | Privacy Policy