Permalink
Browse files

Create skeleton application runner

  • Loading branch information...
1 parent 36f83e4 commit 050afc849fcb48687fa16124a5e3314e58603e9c @mdippery committed Dec 1, 2012
Showing with 49 additions and 0 deletions.
  1. +5 −0 bin/usaidwat
  2. +8 −0 features/help.feature
  3. +1 −0 lib/usaidwat.rb
  4. +35 −0 lib/usaidwat/application.rb
View
5 bin/usaidwat
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require 'usaidwat'
+
+USaidWat.application.run(ARGV)
View
8 features/help.feature
@@ -10,3 +10,11 @@ Feature: Get help
"""
Usage: usaidwat [--tally] <user> [<subreddit>]
"""
+
+ Scenario: Get version
+ When I run `usaidwat --version`
+ Then the exit status should be 0
+ And the stdout should contain:
+ """
+ usaidwat v
+ """
View
1 lib/usaidwat.rb
@@ -1 +1,2 @@
+require "usaidwat/application"
require "usaidwat/version"
View
35 lib/usaidwat/application.rb
@@ -0,0 +1,35 @@
+module USaidWat
+ class << self
+ def application
+ @application ||= USaidWat::Application.new
+ end
+ end
+
+ class Application
+ def run(argv)
+ @opts, args = handle_arguments(argv)
+ end
+
+ def usage(code=0)
+ puts "Usage: usaidwat [--tally] <user> [<subreddit>]"
+ exit code
+ end
+
+ def version(code=0)
+ puts "usaidwat v#{USaidWat::VERSION}"
+ end
+
+ private
+ def handle_arguments(argv)
+ usage if argv.first == "--help"
+ version if argv.first == "--version"
+ opts = {:tally => false}
+ if argv.first == "--tally"
+ opts[:tally] = true
+ argv.shift
+ usage(1) if argv.length > 1
+ end
+ [opts, argv]
+ end
+ end
+end

0 comments on commit 050afc8

Please sign in to comment.