Making CLI app in ruby
-
Upload
huy-do -
Category
Engineering
-
view
292 -
download
0
Transcript of Making CLI app in ruby
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 log --UI --word-diffGit
$grep -c false /etc/passwdGrep
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 !
!
• Using REPL makes our app more
interactive
while (line=gets) do #do something with line end
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. "
GNU readline binding for ruby is a built in STL!!!!!!
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
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
This is how my app looks like
R E P O AT H T T P : / / H U Y D X . C O M / FA C Y
Thank you for listening!!!