Making CLI app with ruby
I'm Huy 
@huydx 
I'm software developer base in 
Tokyo, Japan 
Blogger at http://ktmt.github.io
What is CLI app 
• CLI stand for command-line interface 
• Some examples of CLI app 
Git $git log --UI --word-diff 
Grep $grep -c false /etc/passwd 
mysql-cli >mysql 
ruby-irb 2.1.3 :001 > 1 + 1 #2 
single line 
shell 
interactive 
shell
Why making CLI app 
• We are programmers, we live in terminal 
• Good CLI tool make our life easier 
• Using terminal make us feel like a god
Introduce Thor 
erikhuda/thor 
"Thor is a simple and 
efficient tool for building 
self-documenting 
command line utilities." 
Using thor, we can build 
single command line app with ease
Let's make a simple THOR app 
(live coding)
But.....
Single line shell app 
is somewhat boring~~~
Let's make interactive shell app 
using REPL 
• REPL stands for read–eval–print loop 
• REPL can simply be a loop 
! 
while (line=gets) do 
#do something with line 
end 
! 
• Using REPL makes our app more 
interactive
Writing complex 
interactive shell from the 
scratch is hard...
Introduce Readline 
"The GNU Readline library 
provides a set of functions for 
use by applications that allow 
users to edit command lines as 
they are typed in. " 
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html 
GNU readline binding for 
ruby is a built in STL!!!!!!
What Readline capable of 
• Customize-able prompt!!! 
• Manage-able history 
• Auto completion 
• Interchange-able editing mode (vim, emacs)
Let's make a simple Readline app 
(live coding)
Some tips to make better CLI app 
• Do one thing 
• Playing well with Others (streams, exit code) 
• Have clear, concise purpose 
• Perfect documentation
FACY 
facebook command line app 
huydx.com/facy
This is how my app looks like
REPO AT 
HTTP://HUYDX.COM/FACY
Thank you for listening!!!

Making CLI app in ruby

  • 1.
    Making CLI appwith ruby
  • 2.
    I'm Huy @huydx I'm software developer base in Tokyo, Japan Blogger at http://ktmt.github.io
  • 3.
    What is CLIapp • CLI stand for command-line interface • Some examples of CLI app Git $git log --UI --word-diff Grep $grep -c false /etc/passwd mysql-cli >mysql ruby-irb 2.1.3 :001 > 1 + 1 #2 single line shell interactive shell
  • 4.
    Why making CLIapp • We are programmers, we live in terminal • Good CLI tool make our life easier • Using terminal make us feel like a god
  • 6.
    Introduce Thor erikhuda/thor "Thor is a simple and efficient tool for building self-documenting command line utilities." Using thor, we can build single command line app with ease
  • 7.
    Let's make asimple THOR app (live coding)
  • 8.
  • 9.
    Single line shellapp is somewhat boring~~~
  • 10.
    Let's make interactiveshell app using REPL • REPL stands for read–eval–print loop • REPL can simply be a loop ! while (line=gets) do #do something with line end ! • Using REPL makes our app more interactive
  • 11.
    Writing complex interactiveshell from the scratch is hard...
  • 12.
    Introduce Readline "TheGNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in. " http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html GNU readline binding for ruby is a built in STL!!!!!!
  • 13.
    What Readline capableof • Customize-able prompt!!! • Manage-able history • Auto completion • Interchange-able editing mode (vim, emacs)
  • 14.
    Let's make asimple Readline app (live coding)
  • 15.
    Some tips tomake better CLI app • Do one thing • Playing well with Others (streams, exit code) • Have clear, concise purpose • Perfect documentation
  • 16.
    FACY facebook commandline app huydx.com/facy
  • 17.
    This is howmy app looks like
  • 18.
  • 19.
    Thank you forlistening!!!