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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akito0107
June 27, 2019
Technology
570
1
Share
TypeScriptのコマンドラインパーサー
Akito0107
June 27, 2019
More Decks by Akito0107
See All by Akito0107
テスタビリティの高いGoのAPIサーバを開発しよう
akito0107
2
8.8k
Node学園 25限 Introduction to Rust
akito0107
6
1.5k
Starting TDD with Node.js
akito0107
3
6k
Other Decks in Technology
See All in Technology
独断と偏見で試してみる、 シングル or マルチエージェント どっちがいいの?
shichijoyuhi
1
240
2026年春のAgentCoreアプデ 細かいやつ全部まとめ
minorun365
3
200
オライリーイベント登壇資料「鉄リサイクル・産廃業界におけるAI技術実応用のカタチ」
takarasawa_
0
220
ServiceによるKubernetes通信制御ーClusterIPを例に
miku01
1
140
ファインディの事業拡大を支える 拡張可能なデータ基盤へのリアーキテクチャ
hiracky16
0
900
QAエンジニアはどうやって プロダクト議論の場に入れるのか?
moritamasami
2
400
アクセシビリティはすべての人のもの
tomokusaba
0
270
Oracle Cloud Infrastructure:2026年4月度サービス・アップデート
oracle4engineer
PRO
0
340
VespaのParent Childを用いたフィードパフォーマンスの改善
taking
0
260
試作とデモンストレーション / Prototyping and Demonstrations
ks91
PRO
0
190
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
360
ハーネスエンジニアリング入門
knishioka
0
120
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
190
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
280
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
200
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
160
4 Signs Your Business is Dying
shpigford
187
22k
Into the Great Unknown - MozCon
thekraken
41
2.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
220
Discover your Explorer Soul
emna__ayadi
2
1.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ܕਪ͕όϦόϦޮ͘ίϚϯυϥ ΠϯπʔϧΛ࡞ͬͨ • όάͳͲ͋Γ·ͨ͠Β࿈བྷ͍ͯͩ͘͠͞ʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠