diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index d90ceed..a84db53 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,7 +9,7 @@ name: Kommand Test on: push: - branches: [ "main", "dev", "v2.0" ] + branches: [ "main", "dev" ] pull_request: branches: [ "main" ] workflow_dispatch: diff --git a/README.md b/README.md index a072a71..93ed000 100644 --- a/README.md +++ b/README.md @@ -4,39 +4,44 @@ # Kommand -Kotlin Native library for create subprocesses and handle their I/O. +Kotlin Native library for create sub-process and redirect their I/O. -# Supported Platforms - -- macOS-X64 -- macOS-Arm64 -- linux-X64 -- linux-Arm64 -- mingw-X64 -- JVM +# v2.0.0 -# Architecture +Rust is an excellent language that takes into account both performance and engineering. -![architecture](assets/architecture_3.0.png) +In version 1.x, we use the following API to provide the function of creating child processes -# Dependent +- `fork` of [POSIX api] +- `CreateChildProcess` of [win32 api] +- `java.lang.ProcessBuilder` of JVM -- Heavily inspired by the rust-std `Command`. -- Based on the `ktor-io`, Inter-Process Communication(IPC) can be handled using pipes -- Kotlin Multiplatform 1.7.20 with new memory manager +In version 2.0, we use the Rust standard library to provide the function of creating child processes. -- ### Native for macOS/Linux +- `std::process::Command` of Rust +- `java.lang.ProcessBuilder` of JVM - System calls using POSIX api +It will bring -- ### Native for Mingw +- More unified API +- Easier to use API +- Performance is still excellent +- Easier to maintain +- Code structure is clearer - System calls using Win32 api +# Supported Platforms -- ### JVM +- x86_64-apple-darwin +- aarch64-apple-darwin +- x86_64-unknown-linux-gnu +- aarch64-unknown-linux-gnu +- x86_64-pc-windows-gnu (mingw-w64) +- jvm - Based `java.lang.ProcessBuilder` +# Dependent +- Rust Standard Library 1.69.0 +- Kotlin Multiplatform 1.9.21 # Usage @@ -54,7 +59,8 @@ repositories { // …… dependencies { - implementation("com.kgit2:kommand:$lastVersion") + // should replace with the latest version + implementation("com.kgit2:kommand:2.x") } ``` @@ -63,37 +69,54 @@ dependencies { ### Inherit Standard I/O +https://github.com/kgit2/kommand/kommand-examples/example1/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L12 + ```kotlin -Command("ping") - .arg("-c") - .args("5", "localhost") - .spawn() - .wait() +import com.kgit2.kommand.process.Command +import com.kgit2.kommand.process.Stdio + +fun main() { + Command("ping") + .args(listOf("-c", "5", "localhost")) + .stdout(Stdio.Inherit) + .spawn() + .wait() +} ``` ### Piped I/O +https://github.com/kgit2/kommand/kommand-examples/example2/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L15 + ```kotlin -val child = Command("ping") - .args("-c", "5", "localhost") - .stdout(Stdio.Pipe) - .spawn() -val stdoutReader: com.kgit2.io.Reader? = child.getChildStdout() -val lines: Sequence = stdoutReader?.lines() -lines.forEach { - println(it) +import com.kgit2.kommand.process.Command +import com.kgit2.kommand.process.Stdio + +fun main() { + val child = Command("ping") + .args(listOf("-c", "5", "localhost")) + .stdout(Stdio.Pipe) + .spawn() + child.bufferedStdout()?.lines()?.forEach { line -> + println(line) + } + child.wait() } -child.wait() ``` ### Null I/O ```kotlin -Command("gradle") - .arg("build") - .stdout(Stdio.Null) - .spawn() - .wait() +import com.kgit2.kommand.process.Command +import com.kgit2.kommand.process.Stdio + +fun main() { + Command("echo") + .arg("nothing") + .stdout(Stdio.Null) + .spawn() + .wait() +} ``` ## Build diff --git a/kommand-examples/example3/src/commonMain/kotlin/com/kgit2/kommand/Main.kt b/kommand-examples/example3/src/commonMain/kotlin/com/kgit2/kommand/Main.kt index af98d4a..207e606 100644 --- a/kommand-examples/example3/src/commonMain/kotlin/com/kgit2/kommand/Main.kt +++ b/kommand-examples/example3/src/commonMain/kotlin/com/kgit2/kommand/Main.kt @@ -4,10 +4,9 @@ import com.kgit2.kommand.process.Command import com.kgit2.kommand.process.Stdio fun main() { - Command("ping") - .args(listOf("-c", "5", "localhost")) - .stdout(Stdio.Inherit) + Command("echo") + .arg("nothing") + .stdout(Stdio.Null) .spawn() .wait() - TODO("Need other more representative examples") }