Slide 1

Slide 1 text

Building Command-line Applications in Ruby

Slide 2

Slide 2 text

Hector Castro Technical Evangelist at Basho @hectcastro

Slide 3

Slide 3 text

Types of Command-line Interfaces

Slide 4

Slide 4 text

$ # non-interactive example $

Slide 5

Slide 5 text

$ # non-interactive example $ mv deal-with-it.gif ~/gifs $

Slide 6

Slide 6 text

$ # interactive example $

Slide 7

Slide 7 text

$ # interactive example $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/hector/.ssh/id_rsa):

Slide 8

Slide 8 text

$ # interactive example $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/hector/.ssh/id_rsa): Created directory '/Users/hector/.ssh'. Enter passphrase (empty for no passphrase):

Slide 9

Slide 9 text

$ # interactive example $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/hector/.ssh/id_rsa): Created directory '/Users/hector/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again:

Slide 10

Slide 10 text

$ # interactive example $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/hector/.ssh/id_rsa): Created directory '/Users/hector/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/hector/.ssh/id_rsa. Your public key has been saved in /Users/hector/.ssh/id_rsa.pub.

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Checklist for a Non-interactive CLI

Slide 13

Slide 13 text

$ # reduce interactivity and unnecessary output $

Slide 14

Slide 14 text

$ # reduce interactivity and unnecessary output $ mv deal-with-it.gif ~/gifs $

Slide 15

Slide 15 text

$ # emit accurate exit status $

Slide 16

Slide 16 text

$ # emit accurate exit status $ mv deal-with-it.gif ~/gifs $

Slide 17

Slide 17 text

$ # emit accurate exit status $ mv deal-with-it.gif ~/gifs $ echo $? 0 $

Slide 18

Slide 18 text

$ # emit accurate exit status $

Slide 19

Slide 19 text

$ # emit accurate exit status $ mv cats.gif ~/gifs mv: rename cats.gif to /Users/hector/gifs: No such file or directory $

Slide 20

Slide 20 text

$ # emit accurate exit status $ mv cats.gif ~/gifs mv: rename cats.gif to /Users/hector/gifs: No such file or directory $ echo $? 1 $

Slide 21

Slide 21 text

$ # have a concise name $

Slide 22

Slide 22 text

$ # have a concise name $ svn co file:///does/anyone/use/me/anymore answer A answer/nope.txt Checked out revision 20. $

Slide 23

Slide 23 text

$ # respect single and multi-letter options $

Slide 24

Slide 24 text

$ # respect single and multi-letter options $ heroku -h << HELP CONTENT >> $

Slide 25

Slide 25 text

$ # respect single and multi-letter options $ heroku -h << HELP CONTENT >> $ heroku --help << HELP CONTENT >>

Slide 26

Slide 26 text

$ # ensure that you provide a --help option $

Slide 27

Slide 27 text

$ # ensure that you provide a --help option $ dd -h dd: unknown operand -h $

Slide 28

Slide 28 text

$ # ensure that you provide a --help option $ dd -h dd: unknown operand -h $ dd --help dd: unknown operand --help

Slide 29

Slide 29 text

$ # use STDOUT correctly $

Slide 30

Slide 30 text

$ # use STDOUT correctly $ curl https://api.github.com/users/hectcastro > hector.json

Slide 31

Slide 31 text

$ # use STDOUT correctly $ curl https://api.github.com/users/hectcastro > hector.json $ cat hector.json | jq ".name" "Hector Castro"

Slide 32

Slide 32 text

$ # use STDERR correctly $

Slide 33

Slide 33 text

$ # use STDERR correctly $ curl joker://api.github.com/users/hectcastro curl: (1) Protocol joker not supported or disabled in libcurl

Slide 34

Slide 34 text

$ # use STDERR correctly $ curl joker://api.github.com/users/hectcastro curl: (1) Protocol joker not supported or disabled in libcurl $ curl joker://api.github.com/users/hectcastro > error.txt 2>&1

Slide 35

Slide 35 text

$ # use STDERR correctly $ curl joker://api.github.com/users/hectcastro curl: (1) Protocol joker not supported or disabled in libcurl $ curl joker://api.github.com/users/hectcastro > error.txt 2>&1 $ cat error.txt curl: (1) Protocol joker not supported or disabled in libcurl

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content