SlideShare a Scribd company logo
Ruby on Rails In Practice
Apartment List and Thoughtbot
San Francisco, September 2012




                    Getting started with
               Command Line Applications
Ruby on Rails In Practice
Apartment List and Thoughtbot
San Francisco, September 2012




                    Getting started with
               Command Line Applications




                                Nikhil Mungel
                                    @hyfather
Why CLI ?
CLI
Scriptable



CLI        Lightweight



 Consistent UX
Why Ruby?
Introducing Command Line Applications with Ruby
•   Textual Manipulation


•   OO & FP Abstractions


•   Plethora of CLI gems


• Examples to learn from
The Structure
Introducing Command Line Applications with Ruby
Input   Execution   Output
Input   Execution   Output




 STDIO = UI/UX
Input



        STDIN
Input


        ARGV/ENV

          STDIN
Input


        ARGV/ENV

          STDIN
Input


        ARGV/ENV

          STDIN
Input
        OptionParser

        ARGV/ENV

          STDIN
Input
        OptionParser

        ARGV/ENV

          STDIN
Input   Libraries
        OptionParser

        ARGV/ENV

          STDIN
Input   Libraries
        OptionParser

        ARGV/ENV

          STDIN
Input   Libraries
        OptionParser

        ARGV/ENV

          STDIN
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: example.rb [options]"

  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end
end.parse!
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: example.rb [options]"

  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end
end.parse!




~ > ./opt.rb --help
Usage: example.rb [options]
   -v, --[no-]verbose               Run verbosely
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: example.rb [options]"

  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end
end.parse!




~ > ./opt.rb --help
Usage: example.rb [options]
   -v, --[no-]verbose               Run verbosely
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: example.rb [options]"

  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end
end.parse!




~ > ./opt.rb --help
Usage: example.rb [options]
   -v, --[no-]verbose               Run verbosely
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: example.rb [options]"

  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end
end.parse!




~ > ./opt.rb --help
Usage: example.rb [options]
   -v, --[no-]verbose               Run verbosely
The Mixlib Suite
class MyCLIApp
  include Mixlib::CLI

  option :config_file,
    :short => "-c CONFIG",
    :description => "Configuration file",
    :required => true
end




~ > ./mycliapp.rb --help
Usage: ./mix.rb (options)
    -c, --config CONFIG      Configuration file (required)
    -h, --help               Show this message
class MyCLIApp
  include Mixlib::CLI

  option :config_file,
    :short => "-c CONFIG",
    :description => "Configuration file",
    :required => true
end




~ > ./mycliapp.rb --help
Usage: ./mix.rb (options)
    -c, --config CONFIG      Configuration file (required)
    -h, --help               Show this message
class MyCLIApp
  include Mixlib::CLI

  option :config_file,
    :short => "-c CONFIG",
    :description => "Configuration file",
    :required => true
end




~ > ./mycliapp.rb --help
Usage: ./mix.rb (options)
    -c, --config CONFIG      Configuration file (required)
    -h, --help               Show this message
config.rb
server_url “http://server.remote”
username   “elvis”
password   “hotdog”
config.rb
server_url “http://server.remote”
username   “elvis”
password   “hotdog”



class MyConfig
  extend(Mixlib::Config)

  server_url 'http://server.local'
  username   'king'
  password   'burger'
end
MyConfig.from_file(‘config.rb’)



irb> MyConfig.server_url
# ‘http://server.remote’
config.rb
server_url “http://server.remote”
username   “elvis”
password   “hotdog”



class MyConfig
  extend(Mixlib::Config)

  server_url 'http://server.local'
  username   'king'
  password   'burger'
end
MyConfig.from_file(‘config.rb’)



irb> MyConfig.server_url
# ‘http://server.remote’
Thor
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
class Test < Thor
  desc " FILE", "an example task"
  method_option :delete,
                :aliases => "-d",
                :desc => "Delete the file"
  def example(file)
  end
end




~ > myapp help test:example
Usage:
  thor test:example FILE

Options:
  -d, [--delete=DELETE]   # Delete the file after parsing it

an example task
Testing!
Introducing Command Line Applications with Ruby
Input   Execution   Output
Input   Execution   Output
Input   Execution   Output




Mostly third party libraries
Input   Execution   Output




Test::Unit, rspec etc.
Input   Execution   Output

         System
System
System


File System    Network   Process
Isolated
 Environments




File System   Network   Process
Isolated
        Environments
User
                                   Container




                     Application



       File System     Network     Process
Streams & Signals
STDO
          UT/S
                 TDER
                        R
                            CLI
User
                            App
       STDIN
STDO
          UT/S
                 TDER
                        R
                            CLI
User
                            App
       STDIN

                                    STDOUT &
                                     STDERR
                            STDIN
                                    Another
                                      App
STDO
          UT/S
                 TDER
                        R
                            CLI
User
                            App
       STDIN

                                    STDOUT &
                                     STDERR
                            STDIN
                                    Another
                                      App
Mixlib::Shellout
> ls = Mixlib::ShellOut.new("ls")
> ls.run_command
> ls.stdout
“init.elnREADME.mdn”




           Nikhil Mungel
   www.hyfather.com     @hyfather
Mixlib::Shellout
> ls = Mixlib::ShellOut.new("ls")
> ls.run_command
> ls.stdout
“init.elnREADME.mdn”




           Nikhil Mungel
   www.hyfather.com     @hyfather
Nikhil Mungel
www.hyfather.com     @hyfather
IO#tty?



        Nikhil Mungel
www.hyfather.com     @hyfather
Output

$stdout    TRACE DEBUG INFO

$stderr    WARN ERROR FATAL



        Nikhil Mungel
www.hyfather.com     @hyfather
Thanks!
I am currently a Grad Student at
         San Jose State

Formerly at ThoughtWorks Studios

       slidesha.re/rubycli
         Nikhil Mungel
 www.hyfather.com     @hyfather

More Related Content

What's hot (20)

PDF
BSDM with BASH: Command Interpolation
Workhorse Computing
 
PPT
Symfony2 Service Container: Inject me, my friend
Kirill Chebunin
 
PDF
用 Go 語言打造多台機器 Scale 架構
Bo-Yi Wu
 
PDF
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Puppet
 
PDF
Shared Object images in Docker: What you need is what you want.
Workhorse Computing
 
PDF
Unit Testing Lots of Perl
Workhorse Computing
 
PDF
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
PPT
On UnQLite
charsbar
 
PPT
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf Conference
 
PDF
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
PDF
Diving into HHVM Extensions (PHPNW Conference 2015)
James Titcumb
 
PDF
Construire son JDK en 10 étapes
José Paumard
 
PDF
Laravel 4 package development
Tihomir Opačić
 
PDF
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
PDF
Smoking docker
Workhorse Computing
 
PPT
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf Conference
 
PDF
PHP traits, treat or threat?
Nick Belhomme
 
PDF
Keeping objects healthy with Object::Exercise.
Workhorse Computing
 
PDF
Information security programming in ruby
Hiroshi Nakamura
 
PDF
Getting Testy With Perl6
Workhorse Computing
 
BSDM with BASH: Command Interpolation
Workhorse Computing
 
Symfony2 Service Container: Inject me, my friend
Kirill Chebunin
 
用 Go 語言打造多台機器 Scale 架構
Bo-Yi Wu
 
Beaker: Automated, Cloud-Based Acceptance Testing - PuppetConf 2014
Puppet
 
Shared Object images in Docker: What you need is what you want.
Workhorse Computing
 
Unit Testing Lots of Perl
Workhorse Computing
 
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
On UnQLite
charsbar
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf Conference
 
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
Diving into HHVM Extensions (PHPNW Conference 2015)
James Titcumb
 
Construire son JDK en 10 étapes
José Paumard
 
Laravel 4 package development
Tihomir Opačić
 
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
Smoking docker
Workhorse Computing
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf Conference
 
PHP traits, treat or threat?
Nick Belhomme
 
Keeping objects healthy with Object::Exercise.
Workhorse Computing
 
Information security programming in ruby
Hiroshi Nakamura
 
Getting Testy With Perl6
Workhorse Computing
 

Viewers also liked (15)

PDF
Railsguide
lanlau
 
PDF
Making CLI app in ruby
Huy Do
 
PDF
Command Line Applications with Ruby
Alexander Merkulov
 
PDF
Slides with notes from Ruby Conf 2014 on using simple techniques to create sl...
Justin Gordon
 
KEY
Rails 3 generators
joshsmoore
 
PDF
Rails Text Mate Cheats
dezarrolla
 
PPTX
Rest and Rails
Chamnap Chhorn
 
KEY
Ruby on Rails Training - Module 1
Mark Menard
 
PDF
Rails01
Al Sayed Gamal
 
PDF
Ruby on Rails Kickstart 103 & 104
Heng-Yi Wu
 
PDF
Ruby on Rails 101
Clayton Lengel-Zigich
 
PDF
Rails 3 Beginner to Builder 2011 Week 3
Richard Schneeman
 
PDF
Developing cross platform desktop application with Ruby
Anis Ahmad
 
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
PDF
Ruby on Rails for beginners
Vysakh Sreenivasan
 
Railsguide
lanlau
 
Making CLI app in ruby
Huy Do
 
Command Line Applications with Ruby
Alexander Merkulov
 
Slides with notes from Ruby Conf 2014 on using simple techniques to create sl...
Justin Gordon
 
Rails 3 generators
joshsmoore
 
Rails Text Mate Cheats
dezarrolla
 
Rest and Rails
Chamnap Chhorn
 
Ruby on Rails Training - Module 1
Mark Menard
 
Ruby on Rails Kickstart 103 & 104
Heng-Yi Wu
 
Ruby on Rails 101
Clayton Lengel-Zigich
 
Rails 3 Beginner to Builder 2011 Week 3
Richard Schneeman
 
Developing cross platform desktop application with Ruby
Anis Ahmad
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Ruby on Rails for beginners
Vysakh Sreenivasan
 
Ad

Similar to Introducing Command Line Applications with Ruby (20)

PDF
Building robust and friendly command line applications in go
Andrii Soldatenko
 
ODP
Devel::hdb debugger talk
abrummett
 
PDF
Living With Legacy Code
Rowan Merewood
 
PPTX
The GO Language : From Beginners to Gophers
I.I.S. G. Vallauri - Fossano
 
PDF
TypeScript for Java Developers
Yakov Fain
 
PDF
Pemrograman Python untuk Pemula
Oon Arfiandwi
 
PDF
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
Codemotion
 
PPTX
Kubernetes walkthrough
Sangwon Lee
 
PDF
Elixir on Containers
Sachirou Inoue
 
PDF
Course 102: Lecture 8: Composite Commands
Ahmed El-Arabawy
 
PDF
Docopt, beautiful command-line options for R, user2014
Edwin de Jonge
 
PDF
Practical pig
trihug
 
PDF
Text mining on the command line - Introduction to linux for bioinformatics
BITS
 
KEY
PyCon AU 2012 - Debugging Live Python Web Applications
Graham Dumpleton
 
PDF
May The Nodejs Be With You
Dalibor Gogic
 
KEY
Django’s nasal passage
Erik Rose
 
PPT
Pluggin creation
Chamilo Association
 
PPT
Easy R
Ajay Ohri
 
PPTX
Z ray plugins for dummies
Dmitry Zbarski
 
PDF
CMake Tutorial
Fu Haiping
 
Building robust and friendly command line applications in go
Andrii Soldatenko
 
Devel::hdb debugger talk
abrummett
 
Living With Legacy Code
Rowan Merewood
 
The GO Language : From Beginners to Gophers
I.I.S. G. Vallauri - Fossano
 
TypeScript for Java Developers
Yakov Fain
 
Pemrograman Python untuk Pemula
Oon Arfiandwi
 
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
Codemotion
 
Kubernetes walkthrough
Sangwon Lee
 
Elixir on Containers
Sachirou Inoue
 
Course 102: Lecture 8: Composite Commands
Ahmed El-Arabawy
 
Docopt, beautiful command-line options for R, user2014
Edwin de Jonge
 
Practical pig
trihug
 
Text mining on the command line - Introduction to linux for bioinformatics
BITS
 
PyCon AU 2012 - Debugging Live Python Web Applications
Graham Dumpleton
 
May The Nodejs Be With You
Dalibor Gogic
 
Django’s nasal passage
Erik Rose
 
Pluggin creation
Chamilo Association
 
Easy R
Ajay Ohri
 
Z ray plugins for dummies
Dmitry Zbarski
 
CMake Tutorial
Fu Haiping
 
Ad

Recently uploaded (20)

PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 

Introducing Command Line Applications with Ruby

  • 1. Ruby on Rails In Practice Apartment List and Thoughtbot San Francisco, September 2012 Getting started with Command Line Applications
  • 2. Ruby on Rails In Practice Apartment List and Thoughtbot San Francisco, September 2012 Getting started with Command Line Applications Nikhil Mungel @hyfather
  • 4. CLI
  • 5. Scriptable CLI Lightweight Consistent UX
  • 8. Textual Manipulation • OO & FP Abstractions • Plethora of CLI gems • Examples to learn from
  • 11. Input Execution Output
  • 12. Input Execution Output STDIO = UI/UX
  • 13. Input STDIN
  • 14. Input ARGV/ENV STDIN
  • 15. Input ARGV/ENV STDIN
  • 16. Input ARGV/ENV STDIN
  • 17. Input OptionParser ARGV/ENV STDIN
  • 18. Input OptionParser ARGV/ENV STDIN
  • 19. Input Libraries OptionParser ARGV/ENV STDIN
  • 20. Input Libraries OptionParser ARGV/ENV STDIN
  • 21. Input Libraries OptionParser ARGV/ENV STDIN
  • 22. options = {} OptionParser.new do |opts| opts.banner = "Usage: example.rb [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end end.parse!
  • 23. options = {} OptionParser.new do |opts| opts.banner = "Usage: example.rb [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end end.parse! ~ > ./opt.rb --help Usage: example.rb [options]    -v, --[no-]verbose               Run verbosely
  • 24. options = {} OptionParser.new do |opts| opts.banner = "Usage: example.rb [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end end.parse! ~ > ./opt.rb --help Usage: example.rb [options]    -v, --[no-]verbose               Run verbosely
  • 25. options = {} OptionParser.new do |opts| opts.banner = "Usage: example.rb [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end end.parse! ~ > ./opt.rb --help Usage: example.rb [options]    -v, --[no-]verbose               Run verbosely
  • 26. options = {} OptionParser.new do |opts| opts.banner = "Usage: example.rb [options]" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end end.parse! ~ > ./opt.rb --help Usage: example.rb [options]    -v, --[no-]verbose               Run verbosely
  • 28. class MyCLIApp include Mixlib::CLI option :config_file, :short => "-c CONFIG", :description => "Configuration file", :required => true end ~ > ./mycliapp.rb --help Usage: ./mix.rb (options) -c, --config CONFIG Configuration file (required) -h, --help Show this message
  • 29. class MyCLIApp include Mixlib::CLI option :config_file, :short => "-c CONFIG", :description => "Configuration file", :required => true end ~ > ./mycliapp.rb --help Usage: ./mix.rb (options) -c, --config CONFIG Configuration file (required) -h, --help Show this message
  • 30. class MyCLIApp include Mixlib::CLI option :config_file, :short => "-c CONFIG", :description => "Configuration file", :required => true end ~ > ./mycliapp.rb --help Usage: ./mix.rb (options) -c, --config CONFIG Configuration file (required) -h, --help Show this message
  • 32. config.rb server_url “http://server.remote” username “elvis” password “hotdog” class MyConfig extend(Mixlib::Config) server_url 'http://server.local' username 'king' password 'burger' end MyConfig.from_file(‘config.rb’) irb> MyConfig.server_url # ‘http://server.remote’
  • 33. config.rb server_url “http://server.remote” username “elvis” password “hotdog” class MyConfig extend(Mixlib::Config) server_url 'http://server.local' username 'king' password 'burger' end MyConfig.from_file(‘config.rb’) irb> MyConfig.server_url # ‘http://server.remote’
  • 34. Thor
  • 35. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end
  • 36. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 37. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 38. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 39. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 40. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 41. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 42. class Test < Thor desc " FILE", "an example task" method_option :delete, :aliases => "-d", :desc => "Delete the file" def example(file) end end ~ > myapp help test:example Usage: thor test:example FILE Options: -d, [--delete=DELETE] # Delete the file after parsing it an example task
  • 45. Input Execution Output
  • 46. Input Execution Output
  • 47. Input Execution Output Mostly third party libraries
  • 48. Input Execution Output Test::Unit, rspec etc.
  • 49. Input Execution Output System
  • 51. System File System Network Process
  • 53. Isolated Environments User Container Application File System Network Process
  • 55. STDO UT/S TDER R CLI User App STDIN
  • 56. STDO UT/S TDER R CLI User App STDIN STDOUT & STDERR STDIN Another App
  • 57. STDO UT/S TDER R CLI User App STDIN STDOUT & STDERR STDIN Another App
  • 58. Mixlib::Shellout > ls = Mixlib::ShellOut.new("ls") > ls.run_command > ls.stdout “init.elnREADME.mdn” Nikhil Mungel www.hyfather.com @hyfather
  • 59. Mixlib::Shellout > ls = Mixlib::ShellOut.new("ls") > ls.run_command > ls.stdout “init.elnREADME.mdn” Nikhil Mungel www.hyfather.com @hyfather
  • 61. IO#tty? Nikhil Mungel www.hyfather.com @hyfather
  • 62. Output $stdout TRACE DEBUG INFO $stderr WARN ERROR FATAL Nikhil Mungel www.hyfather.com @hyfather
  • 63. Thanks! I am currently a Grad Student at San Jose State Formerly at ThoughtWorks Studios slidesha.re/rubycli Nikhil Mungel www.hyfather.com @hyfather

Editor's Notes

  • #2: \n
  • #3: \n
  • #4: \n
  • #5: \n
  • #6: \n
  • #7: \n
  • #8: \n
  • #9: \n
  • #10: \n
  • #11: \n
  • #12: \n
  • #13: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #14: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #15: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #16: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #17: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #18: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #19: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #20: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #21: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #22: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #23: Input - command line -&gt; Option Parsing\n\nOutput - status code, stdout, stderr\n
  • #24: \n
  • #25: \n
  • #26: \n
  • #27: \n
  • #28: \n
  • #29: \n
  • #30: \n
  • #31: \n
  • #32: \n
  • #33: \n
  • #34: \n
  • #35: \n
  • #36: \n
  • #37: \n
  • #38: \n
  • #39: \n
  • #40: \n
  • #41: \n
  • #42: \n
  • #43: \n
  • #44: Enforces OO\nAutomatic rake style tasks\n
  • #45: Enforces OO\nAutomatic rake style tasks\n
  • #46: Enforces OO\nAutomatic rake style tasks\n
  • #47: Convention -- \nfirst arg to the description becomes the input \nsecond arg is the banner\n
  • #48: Convention -- \nfirst arg to the description becomes the input \nsecond arg is the banner\n
  • #49: Convention -- \nfirst arg to the description becomes the input \nsecond arg is the banner\n
  • #50: Option Parsing\nInbuilt support for help and banners\nSupports standard invocations of help on the shell\n
  • #51: Option Parsing\nInbuilt support for help and banners\nSupports standard invocations of help on the shell\n
  • #52: \n
  • #53: \n
  • #54: \n
  • #55: \n
  • #56: Input - mostly handled by the third party library.\nTesting that would be testing the gem. Not a good idea.\n\n
  • #57: Input - mostly handled by the third party library.\nTesting that would be testing the gem. Not a good idea.\n\n
  • #58: Standard Ruby classes. Libraries like test/unit, rspec.\nMocking and proxy layers for 3rd party services etc.\nLike any other app.\n\n
  • #59: \n
  • #60: Mocking\n&amp;#xA0; mocha works out well.&amp;#xA0;\n&amp;#xA0; For filesystem, MockFS lets you mock the entire file system.&amp;#xA0;\n\nTesting CLI apps that manipulate filesystem. Mocking is good. But if we mock every call to FileUtils, test becomes very tightly coupled. So even if behaviour doesn&apos;t change but the command changes the test breaks.\n&amp;#xA0;- one use FakeFS\n\n
  • #61: Mocking\n&amp;#xA0; mocha works out well.&amp;#xA0;\n&amp;#xA0; For filesystem, MockFS lets you mock the entire file system.&amp;#xA0;\n\nTesting CLI apps that manipulate filesystem. Mocking is good. But if we mock every call to FileUtils, test becomes very tightly coupled. So even if behaviour doesn&apos;t change but the command changes the test breaks.\n&amp;#xA0;- one use FakeFS\n\n
  • #62: Isolate environment of its own.\nIf its is cheap and scriptable to spin up the environment. Then we can have behaviour testing&amp;#xA0;\n&amp;#xA0; - powerful machines.\n&amp;#xA0; - strong virtualizations (inbuilt)\nvagrant, lxc, openvz\n
  • #63: Isolate environment of its own.\nIf its is cheap and scriptable to spin up the environment. Then we can have behaviour testing&amp;#xA0;\n&amp;#xA0; - powerful machines.\n&amp;#xA0; - strong virtualizations (inbuilt)\nvagrant, lxc, openvz\n
  • #64: Isolate environment of its own.\nIf its is cheap and scriptable to spin up the environment. Then we can have behaviour testing&amp;#xA0;\n&amp;#xA0; - powerful machines.\n&amp;#xA0; - strong virtualizations (inbuilt)\nvagrant, lxc, openvz\n
  • #65: Isolate environment of its own.\nIf its is cheap and scriptable to spin up the environment. Then we can have behaviour testing&amp;#xA0;\n&amp;#xA0; - powerful machines.\n&amp;#xA0; - strong virtualizations (inbuilt)\nvagrant, lxc, openvz\n
  • #66: Isolate environment of its own.\nIf its is cheap and scriptable to spin up the environment. Then we can have behaviour testing&amp;#xA0;\n&amp;#xA0; - powerful machines.\n&amp;#xA0; - strong virtualizations (inbuilt)\nvagrant, lxc, openvz\n
  • #67: 2 distinct sections -- your and subprocesses\n\nbackticks and system ruby calls not versatile. Doesn&amp;#x2019;t give you full control over the Input/Output/Error stream\nMixLib::Shellout and POpen3 are better alternatives.\nRespect exit status 0 -for success, rest all failures while writing your CLI.\nYour CLI should write error to stderr and not stdout. ruby provides $stdout, $stdin, $stderr\n\n
  • #68: backticks and system ruby calls not versatile. Doesn&amp;#x2019;t give you full control over the Input/Output/Error stream\nMixLib::Shellout and POpen3 are better alternatives.\n\nRespect exit status 0 -for success, rest all failures while writing your CLI.\nYour CLI should write error to stderr and not stdout. ruby provides $stdout, $stdin, $stderr\n
  • #69: backticks and system ruby calls not versatile. Doesn&amp;#x2019;t give you full control over the Input/Output/Error stream\nMixLib::Shellout and POpen3 are better alternatives.\n\nRespect exit status 0 -for success, rest all failures while writing your CLI.\nYour CLI should write error to stderr and not stdout. ruby provides $stdout, $stdin, $stderr\n
  • #70: Compatible with windows.\nUses the select(2) system call. \nGives abstractions over umask, cwd etc.\n
  • #71: Compatible with windows.\nUses the select(2) system call. \nGives abstractions over umask, cwd etc.\n
  • #72: \n
  • #73: STDOUT could be the default. But should be configurable to a file. \n\nLog at correct level. Apply to all apps but worth mentioning.\n\nyou may want to support -v and -vv for falling back to :info or :debug and -q falls back fatal.\n
  • #74: \n