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

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

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

import kotlinx.coroutines.flow.*
import pl.mareklangiewicz.annotations.DelicateApi
import pl.mareklangiewicz.kommand.*

fun isKommandAvailable(kommand: Kommand) = isCommandAvailable(kommand.name)

fun isCommandAvailable(command: String) = whichFirstOrNull(command).reducedMap { this != null }

@OptIn(DelicateApi::class)
fun whichFirstOrNull(command: String) = which(command).reducedOut { firstOrNull() }

@OptIn(DelicateApi::class)
fun which(vararg commands: String, all: Boolean = false) =
  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