Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kotlinx.cliで始めるCLIアプリ開発
Search
Yuta Tomiyama
August 08, 2020
Programming
0
1.2k
kotlinx.cliで始めるCLIアプリ開発
CAMPHOR- LT 2020 Summer にて発表
Yuta Tomiyama
August 08, 2020
Tweet
Share
More Decks by Yuta Tomiyama
See All by Yuta Tomiyama
ビルドプロセスをデバッグしよう!
yt8492
0
360
モバイルアプリ開発を始めよう!
yt8492
0
79
Git勉強会
yt8492
0
170
なんでもやってみる勇気
yt8492
0
110
Android Autoが思ったよりしんどい話
yt8492
0
220
apollo-kotlinにcontributeした話
yt8492
0
160
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
890
今だからこそ知りたいKotlin Multiplatform
yt8492
0
310
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
AIコーディングエージェント(NotebookLM)
kondai24
0
190
Cell-Based Architecture
larchanjo
0
120
愛される翻訳の秘訣
kishikawakatsumi
3
320
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.4k
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
830
Giselleで作るAI QAアシスタント 〜 Pull Requestレビューに継続的QAを
codenote
0
190
Microservices rules: What good looks like
cer
PRO
0
1.4k
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.8k
sbt 2
xuwei_k
0
300
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
4
870
Go コードベースの構成と AI コンテキスト定義
andpad
0
120
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
110
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
390
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
We Have a Design System, Now What?
morganepeng
54
7.9k
How to train your dragon (web standard)
notwaldorf
97
6.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
Rails Girls Zürich Keynote
gr2m
95
14k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Automating Front-end Workflow
addyosmani
1371
200k
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