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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
1
410
モバイルアプリ開発を始めよう!
yt8492
0
95
Git勉強会
yt8492
0
190
なんでもやってみる勇気
yt8492
0
120
Android Autoが思ったよりしんどい話
yt8492
0
240
apollo-kotlinにcontributeした話
yt8492
0
170
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
930
今だからこそ知りたいKotlin Multiplatform
yt8492
0
320
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
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
420
Ruby and LLM Ecosystem 2nd
koic
1
810
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.9k
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
240
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
150
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
960
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
240
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
1
140
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
160
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.2k
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
190
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
1.1k
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Speed Design
sergeychernyshev
33
1.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
550
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
150
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
86
Unsuck your backbone
ammeep
672
58k
What's in a price? How to price your products and services
michaelherold
247
13k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
640
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
230
Art, The Web, and Tiny UX
lynnandtonic
304
21k
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