kommons

Kommons is a set of Kotlin Multiplatform Libraries (MPP) to allow the execution of command lines / scripts, to support print debugging and to ease testing.

MIT License

Stars
16
Committers
2

Bot releases are hidden (Show)

kommons - Test release

Published by bkahlert about 3 years ago

This is a test release to check if the new workflow works.

kommons - Koodies → Kommons

Published by bkahlert about 3 years ago

kommons -

Published by bkahlert about 3 years ago

kommons -

Published by bkahlert about 3 years ago

kommons -

Published by bkahlert about 3 years ago

kommons - v1.6.0 — OpenTelemetry Integration

Published by bkahlert about 3 years ago

kommons - Refactored Kaomoji

Published by bkahlert over 3 years ago

public object Wizards : Category() {
    public val `(ノ>ω<)ノ﹕・゚’★,。・﹕*﹕・゚’☆`: Kaomoji by parts("(ノ", ">", "ω", "<", ")ノ", " :。・:*:・゚’★,。・:*:・゚’☆")
    public val `(# ̄_ ̄)o︠・━・・━・━━・━☆`: Kaomoji by parts(0..1, 2..2, 3..3, 4..4, 5..7, 8..18)
    public val `(/ ̄‿ ̄)/~~☆’․・․・﹕★’․・․・﹕☆`: Kaomoji by parts("(/", " ̄", "‿", " ̄", ")/", "~~☆’.・.・:★’.・.・:☆")
    public val `(∩ᄑ_ᄑ)⊃━☆゚*・。*・﹕≡( ε﹕)`: Kaomoji by parts("(∩", "ᄑ", "_", "ᄑ", ")⊃", "━☆゚*・。*・:≡( ε:)")
    public val `(ノ ˘_˘)ノ ζζζ  ζζζ  ζζζ`: Kaomoji by parts(0..2, 3..3, 4..4, 5..5, 6..7, 8..21)
    public val `(ノ°∀°)ノ⌒・*﹕․。․ ․。․﹕*・゜゚・*☆`: Kaomoji by parts("(ノ", "°", "∀", "°", ")ノ", "⌒・*:.。. .。.:*・゜゚・*☆")
    public val `(⊃。•́‿•̀。)⊃━✿✿✿✿✿✿`: Kaomoji by parts(0..2, 3..4, 5..5, 6..7, 8..10, 11..17)
    public val `ଘ(੭ˊᵕˋ)੭* ੈ✩‧₊˚`: Kaomoji by parts(0..2, 3..3, 4..4, 5..5, 6..7, 8..14)
}
kommons - Koodies Exec: Feature-Rich Process Execution

Published by bkahlert over 3 years ago

What can you run?

⌨️ Command Lines CommandLine("printenv", "HOME").exec()
📄 Shell Scripts ShellScript { "printenv | grep HOME | perl -pe 's/.*?HOME=//'" }.exec()

How can you run?

Degree of Interaction
▶️ executing-only ShellScript { … }.exec()
📝 logging ShellScript { … }.exec.logging()
  • If things go wrong, it's also logged:
    Process {PID} terminated with exit code {…}
    ➜ A dump has been written to:
    - {WorkDir}/koodies.dump.{}.log
    - {WorkDir}/koodies.dump.{}.ansi-removed.log
      ➜ The last 10 lines are:
      {…}
      3
      2
      1
      Boom!
    
🧠 processing ShellScript { … }.exec.processing { io -> doSomething(io) }
  • io is typed; simply use io is IO.Output to filter out errors and meta information
Synchronicity
👯‍♀️ 👯‍♂️ synchronous: ShellScript { … }.exec()
💃 🕺 asynchronous: ShellScript { … }.exec.async()

Where can you run?

💻 Locally ShellScript { … }.exec()
🐳 Dockerized ShellScript { … }.dockerized{ "bkahlert" / "libguestfs" }.exec()
  • use any Docker image you like

Features

Automatically Captured I/O

Whatever variant you choose, life-cycle events, sent input, the process's output and errors are stored for you:

CommandLine(…).exec().io
CommandLine(…).exec().io.output
CommandLine(…).exec().io.error.ansiRemoved
Typed (Exit) State
  • Access the state with state, which is either an instance of Running, Exited
    (with the sub states Succeeded and Failed) or Excepted.
  • All states print nicely and provide a copy of all logged I/O, and state-dependent information such as the exit code.
  • By default, processes are killed on VM shutdown, which can be configured.
  • Life-cycle callbacks can be registered.
Ready to run Docker commands
with(tempDir()) {
    SvgFile.copyTo(resolve("koodies.svg"))

    // convert SVG to PNG using command line-style docker command
    docker("minidocks/librsvg", "-z", 5, "--output", "koodies.png", "koodies.svg")
    resolve("koodies.png") asserting { exists() }

    // convert PNG to ASCII art using shell script-style docker command
    docker("rafib/awesome-cli-binaries", logger = null) {
        """
           /opt/bin/chafa -c full -w 9 koodies.png
        """
    }.io.output.ansiKept.let { println(it.resetLines()) }
}
Output
&kyTTTTTTTTTTTTTTTTTTTTuvvvvvvvvvvvvvvvvvvvvvvvv\.
RR&kyTTTTTTTTTTTTTTTTTvvvvvvvvvvvvvvvvvvvvvvvv\.
BBRR&kyTTTTTTTTTTTTTvvvvvvvvvvvvvvvvvvvvvvvv\.
BBBBRR&kyTTTTTTTTTvvvvvvvvvvvvvvvvvvvvvvvv\.
BBBBBBRR&kyTTTTTvvvvvvvvvvvvvvvvvvvvvvvv\.
BBBBBBBBRR&kyTx}vvvvvvvvvvvvvvvvvvvvvv\.
BBBBBBBBBBRZT}vvvvvvvvvvvvvvvvvvvvvv\.
BBBBBBBBBBQxvvvvvvvvvvvvvvvvvvvvvv\.
BBBBBBBB&xvvvvvvvvvvvvvvvvvvvvvv\.
BBBBBBZzvvvvvvvvvvvvvvvvvvvvvv\.
BBBBZuvvvvvvvvvvvvvvvvvvvvvv▗▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
BBZTvvvvvvvvvvvvvvvvvvvvvv\.▝▜MMMMMMMMMMMMMMMMMMMM
R3vvvvvvvvvvvvvvvvvvvvvv\.   .▝▜MMMMMMMMMMMMMMMMMM
vvvvvvvvvvvvvvvvvvvvvv\.       .▝▜MMMMMMMMMMMMMMMM
vvvvvvvvvvvvvvvvvvvv\.           .▝▜MMMMMMMMMMMMMM
uxvvvvvvvvvvvvvvvvz3x_              ▝▜MMMMMMMMMMMM
▁3uxvvvvvvvvvvvv▁▅&▆▂gx`              ▝▜MMMMMMMMMM
Z▅▁3uxvvvvvvvvz▆WWRZ&▆▂gv.             `▀WMMMMMMMM
WR&▄▁3uxvvvvvuk▀BWWWRZ&▆▂gv.         .\vvz▀WMMMMMM
WWWRZ▅▁3ux▁▂Zg33k▀BWWWRZ&▆▂g}.     .\vvvvvvz▀WMM0W
000WWRZ▅▃▆MM▆▂Zg33k▀BWWWRZ&▆▂g}. .\vvvvvvvvvvx▀BBR
00000WMMMMMMMM▆▂Zg33k▀BWWWRZ&▆▂yxxvvvvvvvvvvvvvx▝▀
0000MMMMMMMMMMMM▆▂Zg33k▀BWWWRZ▆▆▂gTxvvvvvvvvvvvvvx
00MMMMMMMMMMMMMMMM▆▂Zg33k▀BWWWRZ&▆▂gTxvvvvvvvvvvvv
MMMMMMMMMMMMMMMMMMMM▆▂Zg33g▀BWWWRZ&▆▂gTxvvvvvvvvvv
  • All docker commands (docker, ubuntu, busybox, curl, download, …) use the path in the receiver to
    • set the working directory of both the host command and the docker container
    • map the host working directory to the container's working directory,
    • that is, all files of that directory are equally available in your container instance.
  • Low level docker commands: start, run, stop, kill, remove, search, image, ps
  • Object-oriented design
    • Docker: engineRunning, info, images, containers, search, exec
    • DockerImage: list, isPulled, pull, tagsOnDockerHub
    • DockerContainer: start, stop, state, kill, remove
  • See ExecutionIntegrationTest.kt and
    Docker.kt for more examples.
kommons - Koodies 1.3.0

Published by bkahlert over 3 years ago

kommons - Koodies 1.2.3

Published by bkahlert almost 4 years ago

kommons -

Published by bkahlert almost 4 years ago

kommons -

Published by bkahlert almost 4 years ago