+ All Categories
Home > Engineering > Making CLI app in ruby

Making CLI app in ruby

Date post: 13-Jul-2015
Category:
Upload: huy-do
View: 292 times
Download: 0 times
Share this document with a friend
Popular Tags:
19
Making CLI app with ruby
Transcript
Page 1: Making CLI app in ruby

Making CLI app with ruby

Page 2: Making CLI app in ruby

I'm Huy

@huydx

I'm software developer base in Tokyo, Japan

Blogger at http://ktmt.github.io

Page 3: Making CLI app in ruby

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

Page 4: Making CLI app in ruby

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

Page 5: Making CLI app in ruby
Page 6: Making CLI app in ruby

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

Page 7: Making CLI app in ruby

Let's make a simple THOR app (live coding)

Page 8: Making CLI app in ruby

But.....

Page 9: Making CLI app in ruby

Single line shell app is somewhat boring~~~

Page 10: Making CLI app in ruby

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

Page 11: Making CLI app in ruby

Writing complex interactive shell from the

scratch is hard...

Page 12: Making CLI app in ruby

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

Page 13: Making CLI app in ruby

What Readline capable of

• Customize-able prompt!!!

• Manage-able history

• Auto completion

• Interchange-able editing mode (vim, emacs)

Page 14: Making CLI app in ruby

Let's make a simple Readline app (live coding)

Page 15: Making CLI app in ruby

Some tips to make better CLI app

• Do one thing

• Playing well with Others (streams, exit code)

• Have clear, concise purpose

• Perfect documentation

Page 16: Making CLI app in ruby

FA C Yfacebook command line app

huydx.com/facy

Page 17: Making CLI app in ruby

This is how my app looks like

Page 18: Making CLI app in ruby

R E P O AT H T T P : / / H U Y D X . C O M / FA C Y

Page 19: Making CLI app in ruby

Thank you for listening!!!


Recommended