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
TypeScriptのコマンドラインパーサー
Search
Akito0107
June 27, 2019
Technology
1
470
TypeScriptのコマンドラインパーサー
Akito0107
June 27, 2019
Tweet
Share
More Decks by Akito0107
See All by Akito0107
テスタビリティの高いGoのAPIサーバを開発しよう
akito0107
2
8.3k
Node学園 25限 Introduction to Rust
akito0107
6
1.4k
Starting TDD with Node.js
akito0107
3
5.8k
Other Decks in Technology
See All in Technology
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
230
podman_update_2024-12
orimanabu
1
280
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
ハイテク休憩
sat
PRO
2
160
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
170
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
110
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
760
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
3
310
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
230
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
150
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
328
21k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Designing for humans not robots
tammielis
250
25k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Building Applications with DynamoDB
mza
91
6.1k
How STYLIGHT went responsive
nonsquared
95
5.2k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Unsuck your backbone
ammeep
669
57k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Transcript
TypeScriptͰ ίϚϯυϥΠϯ ύʔαʔ NodeֶԂ34ݶ ҏ౻ɹӯ
ࣗݾհ • ҏ౻ɹӯ (͍ͱ͏ɹ͖͋ͱʣ • @akito0107 • όοΫΤϯυΤϯδχΞ • Go
/ TypeScriptΛॻ͍͍ͯ·͢ • https://blog.akito0107.dev
࣍ • ίϚϯυϥΠϯύʔαʔΛ࡞ͬͨ • ͳͥ࡞͔ͬͨ • Demo • ͍ํʹ͍ͭͯ
Node.jsͰ ίϚϯυϥΠϯπʔϧΛ࡞Δ • ҎԼͷΑ͏ͳϥΠϒϥϦ͕༗໊ • substack/minimist • tj/commander • cacjs/cac
• yargs/yargs • ෳࡶͳΦϓγϣϯΛύʔε͢Δͱ͖ʹਏ͍
Option Hell • ex) kubectl
Sub command ͭΒ͍
ίϚϯυϥΠϯͷΦϓγϣϯ • ͋ΔఔෳࡶͳίϚϯυΛ࣮͠Α͏ͱͨ͠ ߹ɺΦϓγϣϯͷ͕Ͳ͏ͯ͠Ε্ ͕ͬͯ͠·͏ • طଘϥΠϒϥϦͰෳࡶͳΦϓγϣϯΛѻ͓͏ ͱ͢Δͱݫ͍͠(ͱࢥͬͯΔ)
ex) commander
ex) commander ܕ͕΄͍͠ʂʂʂʂ
ܕ͕ͭͭ͘Λ࡞ͬͨ • https://github.com/akito0107/marron-glace • σϞ
ϑϥάͷఆٛͷํ • makeStringFlag / makeBooleanFlag … • ͜ΕΒͷؔʹɺϑϥάͷ໊લͱΦϓγϣϯ ʢσϑΥϧτ࣌ͷɺhelpͰදࣔ͢Δจݴͳ ͲʣΛ͢
<= Stringͷͱ͖stringҎ֎ڐ༰͠ͳ͍ <=helpͷͱ͖ͷจݴ <= -s Ͱड͚ΒΕΔΑ͏ʹ —flag1 ͷϑϥάΛఆٛ —flag2 ͷϑϥάΛఆٛ
ϑϥάͷreduce • reduceFlagͰෳͷϑϥάΛ·ͱΊΔ • reduceFlagͷฦΓflagͳͷͰɺ࠶ reduce͢Δ͜ͱ͕Ͱ͖Δ
makeCommand • flagΛmakeCommandͷύϥϝʔλʹ͢ <= ͜ͷ͋ͨΓhelpͰग़ͭ͢
(positional)Arguments • `mv src target` ͷsrc, targetͷΑ͏ʹɺίϚϯ υʹΘͨ͢Ҿܕ͖Ͱαϙʔτ
makeCommandʹΘͨ͢ <= ͜͜ʹิ͕ޮ͘
Sub commands • makeSubcommandHandlerΛ͏ <= ͜͜ʹsubCommandΛ͍ΕΔ
Sub commandΛ࡞Δ <= ίϚϯυͷflag <= subίϚϯυͷflag ↑ ίϚϯυͱreduce͢Δ <- ίϚϯυͷflagͱ
subίϚϯυͷflag͕྆ํ͑Δ
ͦͷଞ • —helpͰϔϧϓίϚϯυ • ಠࣗܕͷflag • ৄ͘͠ϒϩάʹ
·ͱΊ • TypeScriptܕਪ͕όϦόϦޮ͘ίϚϯυϥ ΠϯπʔϧΛ࡞ͬͨ • όάͳͲ͋Γ·ͨ͠Β࿈བྷ͍ͯͩ͘͠͞ʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠