SlideShare a Scribd company logo
CLI
(Shengyou Fan)
COSCUP 2021
JVM
2021/08/01
Photo by Markus Spiske on Unsplash
JetBrains
Kotlin Open Source
Kotlin
—
• General-purpose
• Static typing
• OOP + FP
• Developed by
JetBrains
• Open Source
(Apache 2.0)
https://kotlinlang.org/
Command Line
2021
Shell (computing)
—
a shell is a computer program which exposes an operating
system's services to a human user or other program.
— From Wikipedia
GUI
CLI
!
Kotlin CLI
CLI
—
Input Output
IntelliJ IDEA
—
—
Kotlin
—
fun main() {
println("A sample CLI app")
}
Kotlin
—
fun main(args: Array<String>) {
args.forEachIndexed { index, string ->
println("($index): $string")
}
}
Fat Jar
—
plugins {
id("com.github.johnrengelman.shadow") version "6.1.0"
}
application {
mainClassName = "io.kraftsman.MainKt"
}
Jar
—
$ java -jar {cli_app_name}.jar
CLI
—
$ {cli_name} {command} arguments [options]
$ ./tree generate 10 --char=#
CLI
—
• / / Command
• / / Argument
• / / Option
•
•
"
Clikt
—
•
•
•
https://ajalt.github.io/clikt/
—
// gradle.properties
clikt_version=3.2.0
// build.gradle.kts
val clikt_version: String by project
dependencies {
implementation("com.github.ajalt.clikt:clikt:$ver")
}
—
class Hello: CliktCommand() {
override fun run() {
echo("Hello World!")
}
}
fun main(args: Array<String>) = Hello().main(args)
Command
—
class Database: CliktCommand() {
override fun run() = Unit
}
class Init: CliktCommand(help="Initialize the database") {
override fun run() {
echo("Initialized the database.")
}
}
class Drop: CliktCommand(help="Drop the database") {
override fun run() {
echo("Dropped the database.")
}
}
fun main(args: Array<String>) = Database()
.subcommands(Init(), Drop())
.main(args)
Argument
—
class Hello : CliktCommand() {
val name by argument()
override fun run() {
echo("Hello $name!")
}
}
Option
—
class Hello : CliktCommand() {
val count by option(help="Number of greetings")
.int()
.default(1)
val name by argument()
override fun run() {
for (i in 1..count) {
echo("Hello $name!")
}
}
}
#
ASCII
!
—
https://kotlinlang.org/docs/reference/native-overview.html https://www.graalvm.org/
GraalVM
—
•
•
https://www.graalvm.org
GraalVM
—
# SDKMAN
$ curl -s "https://get.sdkman.io" | bash
# GraalVM
$ sdk install java 21.1.0.r16-grl
# Java
$ sdk use java 21.1.0.r16-grl
# Native Image
$ gu install native-image
—
# Java
$ sdk use java 20.3.0.r11-grl
# Shadow FatJar
$ ./gradlew shadowJar
# Native Image
$ native-image -jar {jar_location}.jar 
{cli_app_name} 
--no-fallback 
--report-unsupported-elements-at-runtime
—
• Shell
• CLI
• Clikt
• ASCII
•
Kotlin
—
Kotlin Tips
Line Telegram
https://tw.kotlin.tips
Tips
—
https://tw.intellij.tips
—
Coding
Kraftsman
(Shengyou Fan)
shengyou.fan@jetbrains.com
Q&A
—
CLI

More Related Content

What's hot (20)

PDF
Try Jetpack Compose
LutasLin
 
PPT
Spock Framework
Леонид Ставила
 
PDF
Kotlin 2.0을 통해 알아보는 코틀린의 미래
Leonardo YongUk Kim
 
PDF
Kotlin - Better Java
Dariusz Lorenc
 
PPTX
NodeJS guide for beginners
Enoch Joshua
 
PPTX
Kotlin
Rory Preddy
 
PDF
Railway Oriented Programming
Scott Wlaschin
 
PDF
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
Shengyou Fan
 
PDF
Py.test
soasme
 
PDF
Spring Framework - AOP
Dzmitry Naskou
 
PDF
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
Shengyou Fan
 
PDF
Solid NodeJS with TypeScript, Jest & NestJS
Rafael Casuso Romate
 
PPTX
Node.js Express
Eyal Vardi
 
PDF
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
PDF
Deep dive into Coroutines on JVM @ KotlinConf 2017
Roman Elizarov
 
PDF
Understanding docker networking
Lorenzo Fontana
 
PPTX
React js
Oswald Campesato
 
PPTX
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
PPTX
eBPF Basics
Michael Kehoe
 
PDF
初探 Kotlin Multiplatform
Shengyou Fan
 
Try Jetpack Compose
LutasLin
 
Kotlin 2.0을 통해 알아보는 코틀린의 미래
Leonardo YongUk Kim
 
Kotlin - Better Java
Dariusz Lorenc
 
NodeJS guide for beginners
Enoch Joshua
 
Kotlin
Rory Preddy
 
Railway Oriented Programming
Scott Wlaschin
 
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
Shengyou Fan
 
Py.test
soasme
 
Spring Framework - AOP
Dzmitry Naskou
 
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
Shengyou Fan
 
Solid NodeJS with TypeScript, Jest & NestJS
Rafael Casuso Romate
 
Node.js Express
Eyal Vardi
 
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Roman Elizarov
 
Understanding docker networking
Lorenzo Fontana
 
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
eBPF Basics
Michael Kehoe
 
初探 Kotlin Multiplatform
Shengyou Fan
 

More from Shengyou Fan (19)

PDF
[JCConf 2024] Kotlin/Wasm:為 Kotlin 多平台帶來更多可能性
Shengyou Fan
 
PDF
[Kotlin 讀書會第五梯次] 深入淺出 Kotlin 第一章導讀
Shengyou Fan
 
PDF
[WebConf Taiwan 2023] 一份 Zend Engine 外帶!透過 Micro 讓一次打包、多處運行變得可能
Shengyou Fan
 
PDF
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
Shengyou Fan
 
PDF
Using the Exposed SQL Framework to Manage Your Database
Shengyou Fan
 
PDF
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
Shengyou Fan
 
PDF
Composer 經典食譜
Shengyou Fan
 
PDF
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
Shengyou Fan
 
PDF
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
Shengyou Fan
 
PDF
[Kotlin Serverless 工作坊] 單元 2 - 簡介 Kotlin Serverless
Shengyou Fan
 
PDF
[Kotlin Serverless 工作坊] 單元 1 - 開發環境建置
Shengyou Fan
 
PDF
用 Kotlin 打造讀書會小幫手
Shengyou Fan
 
PDF
Kotlin 讀書會第三梯次第一章
Shengyou Fan
 
PDF
用 OPENRNDR 將 Chatbot 訊息視覺化
Shengyou Fan
 
PDF
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
Shengyou Fan
 
PDF
Ktor 部署攻略 - 老派 Fat Jar 大法
Shengyou Fan
 
PDF
以 Kotlin 快速打造 Mobile Backend
Shengyou Fan
 
PDF
Kotlin 一條龍 - 打造全平台應用
Shengyou Fan
 
PDF
[HKOSCon 2020] Build an api service using ktor rapidly
Shengyou Fan
 
[JCConf 2024] Kotlin/Wasm:為 Kotlin 多平台帶來更多可能性
Shengyou Fan
 
[Kotlin 讀書會第五梯次] 深入淺出 Kotlin 第一章導讀
Shengyou Fan
 
[WebConf Taiwan 2023] 一份 Zend Engine 外帶!透過 Micro 讓一次打包、多處運行變得可能
Shengyou Fan
 
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
Shengyou Fan
 
Using the Exposed SQL Framework to Manage Your Database
Shengyou Fan
 
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
Shengyou Fan
 
Composer 經典食譜
Shengyou Fan
 
[Kotlin Serverless 工作坊] 單元 4 - 實作 RSS Aggregator
Shengyou Fan
 
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
Shengyou Fan
 
[Kotlin Serverless 工作坊] 單元 2 - 簡介 Kotlin Serverless
Shengyou Fan
 
[Kotlin Serverless 工作坊] 單元 1 - 開發環境建置
Shengyou Fan
 
用 Kotlin 打造讀書會小幫手
Shengyou Fan
 
Kotlin 讀書會第三梯次第一章
Shengyou Fan
 
用 OPENRNDR 將 Chatbot 訊息視覺化
Shengyou Fan
 
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
Shengyou Fan
 
Ktor 部署攻略 - 老派 Fat Jar 大法
Shengyou Fan
 
以 Kotlin 快速打造 Mobile Backend
Shengyou Fan
 
Kotlin 一條龍 - 打造全平台應用
Shengyou Fan
 
[HKOSCon 2020] Build an api service using ktor rapidly
Shengyou Fan
 
Ad

Recently uploaded (20)

PDF
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
PDF
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PDF
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
PDF
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
PPTX
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
PPTX
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
PDF
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
PDF
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
PDF
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
PPTX
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PDF
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
PPTX
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
PPTX
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
ssuser73bdb11
 
FutureCon Seattle 2025 Presentation Slides - You Had One Job
Suzanne Aldrich
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
Networking_Essentials_version_3.0_-_Module_3.pptx
ryan622010
 
Metaphysics_Presentation_With_Visuals.pptx
erikjohnsales1
 
BRKSP-2551 - Introduction to Segment Routing.pdf
fcesargonca
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
Enhancing Parental Roles in Protecting Children from Online Sexual Exploitati...
ICT Frame Magazine Pvt. Ltd.
 
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
PHIPA-Compliant Web Hosting in Toronto: What Healthcare Providers Must Know
steve198109
 
Orchestrating things in Angular application
Peter Abraham
 
BRKAPP-1102 - Proactive Network and Application Monitoring.pdf
fcesargonca
 
西班牙巴利阿里群岛大学电子版毕业证{UIBLetterUIB文凭证书}文凭复刻
Taqyea
 
Networking_Essentials_version_3.0_-_Module_5.pptx
ryan622010
 
Ad

老派浪漫:用 Kotlin 寫 Command Line 工具