command line suites

with
GLI




Nick Nguyen

@thenicknguyen
nickhxnguyen@gmail.com

The Tea Garden & Steepery Tea Bar
@steepery
www.steepery.com

thing of the past ?

unleash the power


without feeling the pain


ruby script




 $ ruby magic_8ball.rb

command line app


$ curl -v https://google.com


          Executable : "curl"


          Options : "-v"

          Arguments : "https://google.com"

command line suite


$ git --no-pager log --before 2013-01-01

Executable : "git"

Global Options  : "--no-pager"

Command : "log"

Command Options : "before"

Arguments

option flags vs switches



Flag
takes an argument or has a default value

Switch 
acts as a boolean, turn functionality on/off

belly crawler





belly admin site


collection of scripts



Scrape Admin site 

Save to local database

Generate report for date ranges and location

Export to CSV

Tools => command suite ?



Shared Code/Functionality

Common Theme

Graphical UI or Web UI is too much




gli








convention over configuration

gli choices


Ruby's built in OptionParser

Help Documentation System

Cucumber and Aruba for testing

Directory Structure

Gemspec Template

Rakefile


create a scaffold


$ gem install gli $ gli init bellyc crawl report exportCreating dir ./bellyc/lib...
Creating dir ./bellyc/bin...
Creating dir ./bellyc/test...
Created ./bellyc/bin/bellyc
Created ./bellyc/README.rdoc
Created ./bellyc/bellyc.rdoc
Created ./bellyc/bellyc.gemspec
Created ./bellyc/test/default_test.rb
Created ./bellyc/test/test_helper.rb
Created ./bellyc/Rakefile
Created ./bellyc/Gemfile
Created ./bellyc/features
Created ./bellyc/lib/bellyc/version.rb
Created ./bellyc/lib/bellyc.rb

built in help docs


 $ bundle exec bin/bellyc help
NAME bellyc - Describe your application here SYNOPSIS bellyc [global options] command [command options] [arguments...] VERSION 0.0.1 GLOBAL OPTIONS -f, --flagname=The name of the argument - Describe some flag here (default: the default) --help - Show this message -s, --[no-]switch - Describe some switch here --version - Display the program version COMMANDS crawl - Describe crawl here export - Describe export here help - Shows a list of commands or help for one command report - Describe report here

executable


command template


command


generated Help text


 $ bundle exec bin/bellyc help crawl

NAME crawl - Access Belly Website and Download Checkin Data SYNOPSIS bellyc [global options] crawl [command options] COMMAND OPTIONS -i, --[no-]ignore-duplicates - ignore duplicate limit -p, --password=arg - password (default: none) -u, --username=arg - username (default: none)

belly crawling


 $ bundle exec bin/bellyc crawl -u nick@steepery.com -p Pa$$word -i
ADDED 14946275 | 09m-27d-13y 14:19 | veron | 15080 ADDED 14946267 | 09m-27d-13y 14:19 | Renee Y | 15050 ADDED 14946249 | 09m-27d-13y 14:19 | chels | 15080 ADDED 14946245 | 09m-27d-13y 14:19 | Renee Y | 15050 ADDED 14946201 | 09m-27d-13y 14:18 | chels | 15080 ADDED 14946053 | 09m-27d-13y 14:17 | ljrub | 15050 ADDED 14945999 | 09m-27d-13y 14:16 | kanne | 15052 ADDED 14945982 | 09m-27d-13y 14:15 | kanne | 15052 ADDED 14945883 | 09m-27d-13y 14:14 | laurenpatto@msn.com l | 15051 ADDED 14945874 | 09m-27d-13y 14:14 | laurenpatto@msn.com l | 15051 ADDED 14945791 | 09m-27d-13y 14:13 | kguar | 16826 ADDED 14945529 | 09m-27d-13y 14:08 | lito_ | 15052 ADDED 14945496 | 09m-27d-13y 14:07 | holly | 15081 ADDED 14945462 | 09m-27d-13y 14:06 | sjb92 | 15080 ADDED 14945438 | 09m-27d-13y 14:06 | Melinda M | 15051 ADDED 14945405 | 09m-27d-13y 14:05 | kenci | 16826 ADDED 14944708 | 09m-27d-13y 13:54 | eandr | 16826

reporting


 $ bundle exec bin/bellyc help report
NAME report - Display number of new and repeat customers for a given range of dates SYNOPSIS bellyc [global options] report [command options] locations COMMAND OPTIONS -e, --end_date=arg - end_date (format yyyy-mm-dd) (default: 2013-09-29) -s, --start_date=arg - start_date (format yyyy-mm-dd) (default: 2013-09-22)

reporting


 $ bundle exec bin/bellyc report -s 2013-09-01 -e 2013-09-30 
$ bundle exec bin/bellyc report 15050 15051
$ bundle exec bin/bellyc report -s 2013-08-01 -e 2013-09-01 15050
Progress Time: 00:00:10 ===================================================================== 100% Location: 15050 # of total customers: 1124 # of new customers: 169 # of repeat customers in one week: 23 # of repeat customers in two weeks: 42 # of repeat customers in one month: 64


command line libraries


OptionParser

Trollop

Methadone

Highline




command suite alternatives


Thor

Main

Escort


reading


Build Awesome Command-Line Applications in Ruby
by David Bryant Copeland

Kick the bash Habit with Ruby and Methadone
by David Bryant Copeland




belly crawler code


command line gli

By Nick Nguyen

command line gli

  • 1,765