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
480
TypeScriptのコマンドラインパーサー
Akito0107
June 27, 2019
Tweet
Share
More Decks by Akito0107
See All by Akito0107
テスタビリティの高いGoのAPIサーバを開発しよう
akito0107
2
8.4k
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
目標と時間軸 〜ベイビーステップでケイパビリティを高めよう〜
kakehashi
PRO
8
860
手を動かしてレベルアップしよう!
maruto
0
240
株式会社Awarefy(アウェアファイ)会社説明資料 / Awarefy-Company-Deck
awarefy
3
11k
データモデルYANGの処理系を再発明した話
tjmtrhs
0
180
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
19k
Aurora PostgreSQLがCloudWatch Logsに 出力するログの課金を削減してみる #jawsdays2025
non97
1
230
1行のコードから社会課題の解決へ: EMの探究、事業・技術・組織を紡ぐ実践知 / EM Conf 2025
9ma3r
12
4.4k
Snowflake ML モデルを dbt データパイプラインに組み込む
estie
0
110
AWSではじめる Web APIテスト実践ガイド / A practical guide to testing Web APIs on AWS
yokawasa
8
750
AIエージェント元年@日本生成AIユーザ会
shukob
1
240
【詳説】コンテンツ配信 システムの複数機能 基盤への拡張
hatena
0
280
OCI Success Journey OCIの何が評価されてる?疑問に答える事例セミナー(2025年2月実施)
oracle4engineer
PRO
2
180
Featured
See All Featured
Navigating Team Friction
lara
183
15k
Writing Fast Ruby
sferik
628
61k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Site-Speed That Sticks
csswizardry
4
410
How to Ace a Technical Interview
jacobian
276
23k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
How to train your dragon (web standard)
notwaldorf
91
5.9k
YesSQL, Process and Tooling at Scale
rocio
172
14k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
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ܕਪ͕όϦόϦޮ͘ίϚϯυϥ ΠϯπʔϧΛ࡞ͬͨ • όάͳͲ͋Γ·ͨ͠Β࿈བྷ͍ͯͩ͘͠͞ʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠