Skip to content

Commit af7c721

Browse files
committed
Temp
1 parent 15f7e01 commit af7c721

File tree

3 files changed

+68
-46
lines changed

3 files changed

+68
-46
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name: Kommand Test
99

1010
on:
1111
push:
12-
branches: [ "main", "dev", "v2.0" ]
12+
branches: [ "main", "dev" ]
1313
pull_request:
1414
branches: [ "main" ]
1515
workflow_dispatch:

README.md

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,44 @@
44

55
# Kommand
66

7-
Kotlin Native library for create subprocesses and handle their I/O.
7+
Kotlin Native library for create sub-process and redirect their I/O.
88

9-
# Supported Platforms
10-
11-
- macOS-X64
12-
- macOS-Arm64
13-
- linux-X64
14-
- linux-Arm64
15-
- mingw-X64
16-
- JVM
9+
# v2.0.0
1710

18-
# Architecture
11+
Rust is an excellent language that takes into account both performance and engineering.
1912

20-
![architecture](assets/architecture_3.0.png)
13+
In version 1.x, we use the following API to provide the function of creating child processes
2114

22-
# Dependent
15+
- `fork` of [POSIX api]
16+
- `CreateChildProcess` of [win32 api]
17+
- `java.lang.ProcessBuilder` of JVM
2318

24-
- Heavily inspired by the rust-std `Command`.
25-
- Based on the `ktor-io`, Inter-Process Communication(IPC) can be handled using pipes
26-
- Kotlin Multiplatform 1.7.20 with new memory manager
19+
In version 2.0, we use the Rust standard library to provide the function of creating child processes.
2720

28-
- ### Native for macOS/Linux
21+
- `std::process::Command` of Rust
22+
- `java.lang.ProcessBuilder` of JVM
2923

30-
System calls using POSIX api
24+
It will bring
3125

32-
- ### Native for Mingw
26+
- More unified API
27+
- Easier to use API
28+
- Performance is still excellent
29+
- Easier to maintain
30+
- Code structure is clearer
3331

34-
System calls using Win32 api
32+
# Supported Platforms
3533

36-
- ### JVM
34+
- x86_64-apple-darwin
35+
- aarch64-apple-darwin
36+
- x86_64-unknown-linux-gnu
37+
- aarch64-unknown-linux-gnu
38+
- x86_64-pc-windows-gnu (mingw-w64)
39+
- jvm
3740

38-
Based `java.lang.ProcessBuilder`
41+
# Dependent
3942

43+
- Rust Standard Library 1.69.0
44+
- Kotlin Multiplatform 1.9.21
4045

4146
# Usage
4247

@@ -54,7 +59,8 @@ repositories {
5459
// ……
5560

5661
dependencies {
57-
implementation("com.kgit2:kommand:$lastVersion")
62+
// should replace with the latest version
63+
implementation("com.kgit2:kommand:2.x")
5864
}
5965

6066
```
@@ -63,37 +69,54 @@ dependencies {
6369

6470
### Inherit Standard I/O
6571

72+
https://github.com/kgit2/kommand/kommand-examples/example1/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L12
73+
6674
```kotlin
67-
Command("ping")
68-
.arg("-c")
69-
.args("5", "localhost")
70-
.spawn()
71-
.wait()
75+
import com.kgit2.kommand.process.Command
76+
import com.kgit2.kommand.process.Stdio
77+
78+
fun main() {
79+
Command("ping")
80+
.args(listOf("-c", "5", "localhost"))
81+
.stdout(Stdio.Inherit)
82+
.spawn()
83+
.wait()
84+
}
7285
```
7386

7487
### Piped I/O
7588

89+
https://github.com/kgit2/kommand/kommand-examples/example2/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L15
90+
7691
```kotlin
77-
val child = Command("ping")
78-
.args("-c", "5", "localhost")
79-
.stdout(Stdio.Pipe)
80-
.spawn()
81-
val stdoutReader: com.kgit2.io.Reader? = child.getChildStdout()
82-
val lines: Sequence<String> = stdoutReader?.lines()
83-
lines.forEach {
84-
println(it)
92+
import com.kgit2.kommand.process.Command
93+
import com.kgit2.kommand.process.Stdio
94+
95+
fun main() {
96+
val child = Command("ping")
97+
.args(listOf("-c", "5", "localhost"))
98+
.stdout(Stdio.Pipe)
99+
.spawn()
100+
child.bufferedStdout()?.lines()?.forEach { line ->
101+
println(line)
102+
}
103+
child.wait()
85104
}
86-
child.wait()
87105
```
88106

89107
### Null I/O
90108

91109
```kotlin
92-
Command("gradle")
93-
.arg("build")
94-
.stdout(Stdio.Null)
95-
.spawn()
96-
.wait()
110+
import com.kgit2.kommand.process.Command
111+
import com.kgit2.kommand.process.Stdio
112+
113+
fun main() {
114+
Command("echo")
115+
.arg("nothing")
116+
.stdout(Stdio.Null)
117+
.spawn()
118+
.wait()
119+
}
97120
```
98121

99122
## Build

kommand-examples/example3/src/commonMain/kotlin/com/kgit2/kommand/Main.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import com.kgit2.kommand.process.Command
44
import com.kgit2.kommand.process.Stdio
55

66
fun main() {
7-
Command("ping")
8-
.args(listOf("-c", "5", "localhost"))
9-
.stdout(Stdio.Inherit)
7+
Command("echo")
8+
.arg("nothing")
9+
.stdout(Stdio.Null)
1010
.spawn()
1111
.wait()
12-
TODO("Need other more representative examples")
1312
}

0 commit comments

Comments
 (0)