Thor - Building CLI with ruby

A33de8445891945c81e488c9ce71e8cc?s=47 Mann
September 08, 2012

Thor - Building CLI with ruby

Create command-line interface with thor



September 08, 2012


  1. Building command-line interface (CLI) with ruby

  2. I have learnt ruby the rails way.

  3. Then... more and more ruby

  4. A rails app is a ruby app. A ruby app

    may NOT be a rails app.
  5. Today Ruby on CLI

  6. What for? Utility => curl Code Genertor => Rails generator

    Automation => db migration
  7. Hello world puts "Hello world"

  8. My ideal CLI mycli <command> [options]

  9. I need to parse the command and options in mycli

    manually. ARGV or
  10. None
  11. Multiple commands desc "hi", "Say hi" def hi puts "hi

    !" end desc "bye", "Say goodbye" def bye puts "bye !" end
  12. Passing argument desc "hello NAME", "Say hello to <NAME>" def

    hello(name) puts "hello #{name}!" end
  13. 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
  14. Documentation ready

  15. Thanks @lchanmann

  16. References Demo: Checkout thor on