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
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
370
モバイルアプリ開発を始めよう!
yt8492
0
82
Git勉強会
yt8492
0
180
なんでもやってみる勇気
yt8492
0
110
Android Autoが思ったよりしんどい話
yt8492
0
220
apollo-kotlinにcontributeした話
yt8492
0
160
DMM TVのSDカードダウンロード機能を実装した話
yt8492
1
900
今だからこそ知りたい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
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
2k
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
570
Patterns of Patterns
denyspoltorak
0
410
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
2.3k
クラウドに依存しないS3を使った開発術
simesaba80
0
210
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
220
ELYZA_Findy AI Engineering Summit登壇資料_AIコーディング時代に「ちゃんと」やること_toB LLMプロダクト開発舞台裏_20251216
elyza
2
920
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
4
1.2k
TestingOsaka6_Ozono
o3
0
260
ThorVG Viewer In VS Code
nors
0
530
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
37k
チームをチームにするEM
hitode909
0
430
Featured
See All Featured
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
250
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Designing for Performance
lara
610
70k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
51k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
260
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
120
Bash Introduction
62gerente
615
210k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
33
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
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