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
Thor - Building CLI with ruby
Search
Mann
September 08, 2012
Programming
5
590
Thor - Building CLI with ruby
Create command-line interface with thor
Mann
September 08, 2012
Tweet
Share
More Decks by Mann
See All by Mann
From Cambodia to Mizzou
lchanmann
0
36
Khmer ASR using Deep Learning
lchanmann
0
400
Path Finding using Search Algorithms
lchanmann
0
43
The secret to a good life
lchanmann
0
42
Monit - unix monitoring utility
lchanmann
1
110
Techcamp PP
lchanmann
0
110
Trying out Verboice
lchanmann
1
92
CoffeeScript
lchanmann
4
200
Other Decks in Programming
See All in Programming
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
34k
Vueのバリデーション、結局どれを選べばいい? ― 自作バリデーションの限界と、脱却までの道のり ― / Which Vue Validation Library Should We Really Use? The Limits of Self-Made Validation and How I Finally Moved On
neginasu
3
1.7k
CSC305 Lecture 12
javiergs
PRO
0
240
퇴근 후 1억이 거래되는 서비스 만들기 | 내가 AI를 사용하는 방법
maryang
1
140
他言語経験者が Golangci-lint を最初のコーディングメンターにした話 / How Golangci-lint Became My First Coding Mentor: A Story from a Polyglot Programmer
uma31
0
480
KoogではじめるAIエージェント開発
hiroaki404
1
210
三者三様 宣言的UI
kkagurazaka
0
300
Claude Agent SDK を使ってみよう
hyshu
0
1.4k
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
18
9.2k
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
210
O Que É e Como Funciona o PHP-FPM?
marcelgsantos
0
240
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
2
190
The Pragmatic Product Professional
lauravandoore
36
7k
Mobile First: as difficult as doing things right
swwweet
225
10k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
We Have a Design System, Now What?
morganepeng
53
7.9k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
22k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Transcript
Building command-line interface (CLI) with ruby
I have learnt ruby the rails way. http://www.frankwatching.com/wordpress/wp-content/uploads/2007/11/rails.jpg
Then... tryruby.org rubykoans.com rubeque.com more and more ruby
A rails app is a ruby app. A ruby app
may NOT be a rails app.
Today Ruby on CLI
What for? Utility => curl Code Genertor => Rails generator
Automation => db migration
Hello world puts "Hello world"
My ideal CLI mycli <command> [options]
I need to parse the command and options in mycli
manually. ARGV or
None
Multiple commands desc "hi", "Say hi" def hi puts "hi
!" end desc "bye", "Say goodbye" def bye puts "bye !" end
Passing argument desc "hello NAME", "Say hello to <NAME>" def
hello(name) puts "hello #{name}!" end
Parsing options desc "hello NAME", "Say hello to <NAME>" method_options
loudly: false def hello(name) name.upcase! if options[:loudly] puts "hello #{name}!" end
Documentation ready
Thanks @lchanmann
References http://whatisthor.com/ http://yehudakatz.com/2009/01/13/some-thor-news/ http://rubylearning.com/blog/2011/01/03/how-do-i-make-a-command-line-tool-in-ruby/ http://www.bounga.org/ruby/2011/09/12/thor-a-command-line-scripting-tool/ Demo: https://gist.github.com/3688473 Checkout thor on
Github https://github.com/wycats/thor http://whatisthor.com/images/thor.png