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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Akito0107
June 27, 2019
Technology
580
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TypeScriptのコマンドラインパーサー
Akito0107
June 27, 2019
More Decks by Akito0107
See All by Akito0107
テスタビリティの高いGoのAPIサーバを開発しよう
akito0107
2
8.9k
Node学園 25限 Introduction to Rust
akito0107
6
1.5k
Starting TDD with Node.js
akito0107
3
6.1k
Other Decks in Technology
See All in Technology
[ホンマでっか SRE] あなたはなぜ SRE に?
_awache
0
140
作って理解するCoding Agent 〜フレームワークに頼らないピュア Python での実装〜
takapy
4
1.3k
Kiro WebとCloud Sessions
nagisa53
2
200
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.2k
1.5時間を無駄にして学んだwsl2におけるaptとsnapの選択と仕組み
yosaka0123
0
440
Windows の互換機能 - 古いプログラムはなぜ動作できるのか
murachiakira
PRO
0
100
Oracle AI Databaseデータベース・サービス: BaseDB/ExaDB-Dの可用性
oracle4engineer
PRO
1
890
MCPを待つな、パスキーを拡げよう(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
260
現場回帰したデータエンジニアが考える AI 時代のキャリア開発 / Career Development in the Age of AI Perspectives from a Hands-on Data Engineer
medley
0
330
カーネルまで探検して理解するふたつの自動計装
sumiyae
0
310
RelayerというPHPのフレームワークを作った
polidog
PRO
0
140
Kiro5兄弟のいまどきのセキュリティ基礎知識
kentapapa
0
200
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
KATA
mclloyd
PRO
35
15k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
220
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.4k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
630
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
490
Embracing the Ebb and Flow
colly
88
5.1k
My Coaching Mixtape
mlcsv
0
280
First, design no harm
axbom
PRO
2
1.3k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
220
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ܕਪ͕όϦόϦޮ͘ίϚϯυϥ ΠϯπʔϧΛ࡞ͬͨ • όάͳͲ͋Γ·ͨ͠Β࿈བྷ͍ͯͩ͘͠͞ʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠