Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c762a25

Browse files
miaPolyanskayaligee
authored andcommitted
main.kts
^KQA-1651
1 parent fec834e commit c762a25

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

‎jvm/main-kts/MainKts.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ or even as simple as
4040
./script.main.kts
4141
```
4242

43-
provided that the shebang line is added to the script and works in the given OS shell. *(See examples below.)*
43+
provided that the shebang line is added to the script and works in the given OS shell
44+
45+
```
46+
#!/usr/bin/env kotlin
47+
```
4448

4549
### Caching
4650

@@ -60,4 +64,12 @@ including navigation into imported libraries.
6064
[`kotlinx-html` library](https://github.com/Kotlin/kotlinx.html) by JetBrains, to generate HTML output
6165
- [`kotlin-shell.main.kts`](scripts/kotlin-shell.main.kts) demonstrates usage of the
6266
[`kotlin-shell` library](https://github.com/jakubriegel/kotlin-shell) by Jakub Riegel, to execute OS shell commands
63-
with easy interaction with Kotlin code
67+
with easy interaction with Kotlin code and can be executed:
68+
69+
- without arguments - executes "ls -l" command for curren directory
70+
- with argument - executes "wc" command for a file
71+
72+
```
73+
kotlin kotlin-shell.main.kts main-kts/example.txt
74+
```
75+

‎jvm/main-kts/example.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Two roads diverged in a yellow wood,
2+
And sorry I could not travel both
3+
And be one traveler, long I stood
4+
And looked down one as far as I could
5+
To where it bent in the undergrowth.

‎jvm/main-kts/scripts/kotlin-shell.main.kts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#!/usr/bin/env kotlin
22

33
@file:DependsOn("eu.jrie.jetbrains:kotlin-shell-core:0.2.1")
4-
@file:DependsOn("org.slf4j:slf4j-simple:1.7.28")
54
@file:CompilerOptions("-Xopt-in=kotlin.RequiresOptIn")
65
@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
6+
@file:Suppress("OPT_IN_ARGUMENT_IS_NOT_MARKER")
77

8-
import eu.jrie.jetbrains.kotlinshell.shell.*
8+
9+
import eu.jrie.jetbrains.kotlinshell.shell.shell
910

1011
shell {
1112
if (args.isEmpty()) {
13+
"echo this is 'ls -l' command for current directory: ${env("PWD")}"()
1214
"ls -l"()
1315
} else {
1416
var lines = 0
1517
var words = 0
1618
var chars = 0
1719

18-
var wasSpace = false
20+
var wasSpace = true
1921

2022
pipeline {
2123
"cat ${args[0]}".process() pipe
@@ -38,7 +40,7 @@ shell {
3840
}
3941

4042
println("My wc:")
41-
println("$lines $words $chars")
43+
println("$lines $words $chars${args[0]}")
4244
println("System wc:")
4345
"wc ${args[0]}"()
4446
}

‎jvm/main-kts/scripts/kotlinx-html.main.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.0")
44

5-
import kotlinx.html.*; import kotlinx.html.stream.*; import kotlinx.html.attributes.*
5+
import kotlinx.html.*
6+
import kotlinx.html.stream.createHTML
67

78
val addressee = args.firstOrNull() ?: "World"
89

‎jvm/simple-main-kts/simple-main-kts-test/testData/kotlinx-html.smain.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env kotlinc -cp dist/kotlinc/lib/kotlin-main-kts.jar -script
22

33
@file:Repository("https://jcenter.bintray.com")
4-
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.11")
4+
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.8.0")
55

66
import kotlinx.html.*; import kotlinx.html.stream.*; import kotlinx.html.attributes.*
77

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /