lib/augury/cli.rb in augury-0.1.0 vs lib/augury/cli.rb in augury-0.2.0
- old
+ new
@@ -1,12 +1,27 @@
require 'thor'
require 'augury'
module Augury
class CLI < Thor
- desc 'generate USERNAME', 'Generate a fortune file for the given username'
- def generate(username)
- augury = Augury::Fortune.new
- puts augury.tweet_texts(username)
+ desc 'generate USERNAME [PATH]', 'Generate a fortune file for the given username'
+ option :width, :type => :numeric, :aliases => :w
+ option :append, :type => :boolean, :aliases => :a
+ def generate(username, *path)
+ path = File.expand_path(path[0] || username)
+ begin
+ augury = Augury::Fortune.new(
+ username,
+ path,
+ options['width'],
+ options['append']
+ )
+ rescue Augury::TwitterConfigError => e
+ puts e.message
+ exit 1
+ end
+ tweets = augury.tweet_texts
+ augury.write_fortune(augury.format_fortune(tweets))
+ puts "Fortune written out to #{path}"
end
end
end