Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kotlinx.cliで始めるCLIアプリ開発
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yuta Tomiyama
August 08, 2020
Programming
1.2k
0
Share
kotlinx.cliで始めるCLIアプリ開発
CAMPHOR- LT 2020 Summer にて発表
Yuta Tomiyama
August 08, 2020
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
ビルドプロセスをデバッグしよう!
yt8492
2
420
モバイルアプリ開発を始めよう!
yt8492
0
100
Git勉強会
yt8492
0
200
なんでもやってみる勇気
yt8492
0
130
Android Autoが思ったよりしんどい話
yt8492
0
240
apollo-kotlinにcontributeした話
yt8492
0
180
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
950
今だからこそ知りたいKotlin Multiplatform
yt8492
0
330
State management and API calls in Jetpack Compose: Learning Apollo + Jetpack Compose through React Hooks
yt8492
0
1.3k
Other Decks in Programming
See All in Programming
Coding as Prompting Since 2025
ragingwind
0
760
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
410
forteeの改修から振り返るPHPerKaigi 2026
muno92
PRO
3
240
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
180
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
120
「速くなった気がする」をデータで疑う
senleaf24
0
150
瑠璃の宝石に学ぶ技術の声の聴き方 / 【劇場版】アニメから得た学びを発表会2026 #エンジニアニメ
mazrean
0
170
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
2
260
仕様漏れ実装漏れをなくすトレーサビリティAI基盤のご紹介
orgachem
PRO
8
5k
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
2
150
事業会社でのセキュリティ長期インターンについて
masachikaura
0
230
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
140
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
260
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
180
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
510
WCS-LA-2024
lcolladotor
0
520
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
160
A Tale of Four Properties
chriscoyier
163
24k
Making Projects Easy
brettharned
120
6.6k
Odyssey Design
rkendrick25
PRO
2
570
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
How to train your dragon (web standard)
notwaldorf
97
6.6k
Transcript
kotlinx.cliで始める CLIアプリ開発 CAMPHOR- LT 2020 Summer
自己紹介 HN: マヤミト 会津大学26期 (学部3年) Zli 現代表 Twitter: @yt8492 GitHub:
https://github.com/yt8492 好きな技術: Kotlin https://yt8492.com Facebookのすがた Twitterのすがた
もくじ 1. そもそもKotlinでCLIアプリの開発ができるのか? 2. kotlinx.cli の紹介 a. プロジェクトへの導入 b. ArgParser
c. Argument d. Option e. Subcommand 3. デモ
1. そもそもKotlinでCLIアプリ開発ができるのか?
1. そもそもKotlinでCLIアプリ開発ができるのか? A. できます。(できなかったらそもそも今日登壇してない)
前提: KotlinでCLIアプリを開発するには - 実行可能なjarファイルにする - 実行可能なバイナリにする - nodeで実行可能なjsにする
2. kotlinx.cliとは - Kotlinのコマンドラインパーサーライブラリ - Kotlin公式が出している - コマンドやパラメータを宣言的に書ける - マルチプラットフォーム対応
- Kotlin/JVM, Kotlin/JS, Kotlin/Native (公式リポジトリのReadmeより適当に和訳) https://github.com/Kotlin/kotlinx-cli
使用例1
使用例2
kotlinx.cliの導入 方法その1 build.gradleに依存を追加
kotlinx.cliの導入 方法その2(Kotlin/Nativeの場合のみ) build.gradleのターゲットの設定でenableEndorsedLibsをtrueにする
ArgParser コマンドライン引数をパースしてくれるやつ コンストラクタにプログラム名を渡す parseメソッドにコマンドライン引数のString型の配列を渡してパース
Argument そのCLIアプリの主要な引数 例: catで渡すファイル名 type: 引数のタイプ(String, Int, Double, Boolean, Choice)
description: 引数の説明 変数名がそのままargumentの名前になる
Option コマンドのオプション 例: git commit --amend type, description: Argumentと同じ shortName:
-が1つの省略形 Argumentと同じく、変数名がそのままオプション名(fullName)になる デフォルト値や必須のオプションなどを設定可能
Subcommand CLIアプリのサブコマンド 例: git add, git commit Subcommandクラスを継承して実装する Subcommandクラスのコンストラクタに名前と説明を渡す ArgumentとOptionの使い方はほぼ同じ
executeメソッドに実行時の処理を実装する
デモ
使ってみた感想 - めちゃくちゃ楽 - 宣言的に書けるので読みやすい - helpを自動で設定してくれるのが良い - MPP対応なのでいろいろな使い方ができそう -
サーバーの起動時のオプションをkotlinx.cliを使って渡すなど - CLIアプリの場合バイナリにできるKotlin/Nativeと相性が良い
リンク集 kotlinx.cli https://github.com/Kotlin/kotlinx-cli 今回のサンプルアプリ https://github.com/yt8492/CliSample catをKotlin/Nativeで実装しようとしてるやつ(WIP) https://github.com/yt8492/CatKt