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

commonMain.debian.Which.kt Maven / Gradle / Ivy

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
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy