commonMain.debian.Which.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kommandline Show documentation
Show all versions of kommandline Show documentation
Kotlin DSL for popular CLI commands.
The newest version!
package pl.mareklangiewicz.kommand.debian
import kotlinx.coroutines.flow.*
import okio.Path
import pl.mareklangiewicz.annotations.DelicateApi
import pl.mareklangiewicz.kground.io.P
import pl.mareklangiewicz.kommand.*
fun isKommandAvailable(kommand: Kommand): ReducedKommand = isCommandAvailable(kommand.name)
fun isCommandAvailable(command: String): ReducedKommand = whichFirstOrNull(command).reducedMap { this != null }
@OptIn(DelicateApi::class)
fun whichFirstOrNull(command: String): ReducedKommand = which(command).reducedOut { firstOrNull()?.P }
@OptIn(DelicateApi::class)
fun which(vararg commands: String, all: Boolean = false): Which =
which { if (all) -WhichOpt.All; for (c in commands) +c }
@DelicateApi
fun which(init: Which.() -> Unit) = Which().apply(init)
/** [linux man](https://linux.die.net/man/1/which) */
@DelicateApi
data class Which(
override val opts: MutableList = mutableListOf(),
override val nonopts: MutableList = mutableListOf(),
) : KommandTypical {
override val name get() = "which"
}
@DelicateApi
interface WhichOpt : KOptTypical {
/** print all matching path names of each argument */
data object All : KOptS("a"), WhichOpt
}