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
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
220
SSMRunbook作成の勘所_20241120
koichiotomo
3
160
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
飲食店データの分析事例とそれを支えるデータ基盤
kimujun
0
180
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
880
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
10
1.2k
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
180
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
230
Lambdaと地方とコミュニティ
miu_crescent
2
370
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Happy Clients
brianwarren
98
6.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Designing for Performance
lara
604
68k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
How to Ace a Technical Interview
jacobian
276
23k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
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ܕਪ͕όϦόϦޮ͘ίϚϯυϥ ΠϯπʔϧΛ࡞ͬͨ • όάͳͲ͋Γ·ͨ͠Β࿈བྷ͍ͯͩ͘͠͞ʂ
͋Γ͕ͱ͏͍͟͝·ͨ͠