Skip to content

Commit

Permalink
Create skeleton application runner
Browse files Browse the repository at this point in the history
  • Loading branch information
mdippery committed Dec 3, 2012
1 parent 36f83e4 commit 050afc8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bin/usaidwat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'usaidwat'

USaidWat.application.run(ARGV)
8 changes: 8 additions & 0 deletions features/help.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
1 change: 1 addition & 0 deletions lib/usaidwat.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require "usaidwat/application"
require "usaidwat/version"
35 changes: 35 additions & 0 deletions lib/usaidwat/application.rb
Original file line number Diff line number Diff line change
@@ -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.