Skip to content

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.

License

Notifications You must be signed in to change notification settings

bkahlert/kommons

Repository files navigation

Koodies

Koodies

Random Kotlin Goodies

See RELEASING.md for information on how to release versions.

Builders

enum class Features {
    FeatureA, FeatureB, FeatureC
}

val features = EnumSetBuilder.build<Features> {
    +Features.FeatureA + Features.FeatureC
}
fun buildList(init: ListBuilder<String>.() -> Unit) {
    val list = init.build()
}

buildList {
    +"element"
    +existingList
}

Processes

Running a Process

val process = process("echo 'Hello World!'") { io ->
    println("Process did output $io") // process the I/O of any process
}.start()

println(process.exitValue) // 0

println(process.logged(OUT)) // Hello World! 

Running a Shell Script

script {
    shebang()
    line("some command")
    !"""
    a \
    multi-line \
    command
    """
    deleteOnCompletion()
    comment("leave no trace")
}

Automatically Captured I/O

println(process.ioLog)
Executing /some/where/koodies.process.bka.sh
file:///some/where/koodies.process.bka.sh // <- simply click on it in your IDE
starting to install
installing...
completed.

Docker Runner

Docker.busybox("""
  while true; do
  echo "looping"
  sleep 1
  done
""").execute()

Improved Java NIO 2 Integration

Access the Class Path

classPath("file.svg").copyTo(somewhere)

Copy Recursively

directory.copyRecursivelyTo(somewhere)

Fluent API

if (path.notExists()) path.withDirectoriesCreated().createFile()

Kaomoji

Kaomojis.`(#-_-)o´・━・・━・━━・━☆`.random()

Borders, Boxes, ...

 ╭───────────────────────────────────────────────────╮ 
 │                                                   │ 
 │        Done. All tests passed within 1.20s        │ 
 │  All test containers running in CONCURRENT mode.  │ 
 │                                                   │ 
 ╰───────────────────────────────────────────────────╯ 
█ ▉ ▊ ▋ ▌ ▍ ▎ ▏ PILLARS  ▏ ▎ ▍ ▌ ▋ ▊ ▉ █

More

  • Logger

    logging {
      logLine { "lazy log message" }
    }
  • Fixture

    HtmlFile.copyTo(Locations.Temp)
  • Time

    Now.emoji
    if(file.age > 3.minutes) ...
  • Unicode, Code Points & Graphemes

    Named Characters and Dictionary

    Unicode.BoxDrawings.asTable()
    ─	BOX DRAWINGS LIGHT HORIZONTAL
    ━	BOX DRAWINGS HEAVY HORIZONTAL
    │	BOX DRAWINGS LIGHT VERTICAL
    ┃	BOX DRAWINGS HEAVY VERTICAL
    ...

    Process Each Actual Character (and not each char)

    "aⒷ☷\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67".asCodePointSequence() -> "a", "", "", ":woman:" ZWJ, ":woman:", ZWJ, ":girl:", ZWJ, ":girl:"

    Process Each Actual Grapheme (that is, what users perceive as a character)

    "aⒷ☷\uD83D\uDC69\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC67‍‍".asGraphemeSequence() -> "a", "", "", ":family-woman-woman-girl-girl:"
  • Colors & Formatting

    "string in".cyan() + "or" + "bold".bold()
  • JUnit Extensions, e.g.

     @Test
     fun InMemoryLogger.`should work`() {
         logLine { "`、ヽ`ヽ`、ヽ(ノ><)ノ `、ヽ`☂ヽ`、ヽ" }
     }

    leaves the console clean.
    Whereas if run with @Debug annotated or simply as the single test, the logger prints to the console.

     @Debug @Test
     fun InMemoryLogger.`should work`() {
         logLine { "`、ヽ`ヽ`、ヽ(ノ><)ノ `、ヽ`☂ヽ`、ヽ" }
     }
    ╭─────╴MyTest ➜ should work
    │   `、ヽ`ヽ`、ヽ(ノ><)ノ `、ヽ`☂ヽ`、ヽ
    ╰─────╴✔

    Use debug to check what's actually inside a String:

    "a  b\n".debug // a ❲THREE-PER-EM SPACE❳ b ⏎␊
    "" // D800▌﹍ (low surrogate with a missing high surroage)

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages