Slide 1

Slide 1 text

Building command-line interface (CLI) with ruby

Slide 2

Slide 2 text

I have learnt ruby the rails way. http://www.frankwatching.com/wordpress/wp-content/uploads/2007/11/rails.jpg

Slide 3

Slide 3 text

Then... tryruby.org rubykoans.com rubeque.com more and more ruby

Slide 4

Slide 4 text

A rails app is a ruby app. A ruby app may NOT be a rails app.

Slide 5

Slide 5 text

Today Ruby on CLI

Slide 6

Slide 6 text

What for? Utility => curl Code Genertor => Rails generator Automation => db migration

Slide 7

Slide 7 text

Hello world puts "Hello world"

Slide 8

Slide 8 text

My ideal CLI mycli [options]

Slide 9

Slide 9 text

I need to parse the command and options in mycli manually. ARGV or

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Multiple commands desc "hi", "Say hi" def hi puts "hi !" end desc "bye", "Say goodbye" def bye puts "bye !" end

Slide 12

Slide 12 text

Passing argument desc "hello NAME", "Say hello to " def hello(name) puts "hello #{name}!" end

Slide 13

Slide 13 text

Parsing options desc "hello NAME", "Say hello to " method_options loudly: false def hello(name) name.upcase! if options[:loudly] puts "hello #{name}!" end

Slide 14

Slide 14 text

Documentation ready

Slide 15

Slide 15 text

Thanks @lchanmann

Slide 16

Slide 16 text

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