From dbc9e57d0a66ee585893b0b5955078575effc616 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Sat, 26 Jul 2008 12:16:29 -0400 Subject: [PATCH] Made error messages for no accounts and no active account work. --- TODO.txt | 2 +- lib/twitter/cli/helpers.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index 3d7960109..b8a55660f 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,4 +1,4 @@ +* if removing the current account, set a new one * import from .twitter -* check if there is a current account before any methods that use that account * add timeout so it doesn't hang forever like it does now if twitter is down * add progress indicator for timeline and replies as posting has for more visual indication that work is happening \ No newline at end of file diff --git a/lib/twitter/cli/helpers.rb b/lib/twitter/cli/helpers.rb index 6b3a8035a..057a47533 100644 --- a/lib/twitter/cli/helpers.rb +++ b/lib/twitter/cli/helpers.rb @@ -1,6 +1,9 @@ module Twitter module CLI module Helpers + class NoActiveAccount < StandardError; end + class NoAccounts < StandardError; end + def output_tweets(collection, options={}) options.reverse_merge!({ :cache => false, @@ -31,8 +34,8 @@ def base(username=current_account.username, password=current_account.password) end def current_account - @current_account ||= Account.active - exit('No current account.') if @current_account.blank? + @current_account ||= Account.active + raise Account.count == 0 ? NoAccounts : NoActiveAccount if @current_account.blank? @current_account end @@ -46,6 +49,10 @@ def do_work(&block) say("Twitter is unavailable right now. Try again later.") rescue Twitter::CantConnect => msg say("Can't connect to twitter because: #{msg}") + rescue Twitter::CLI::Helpers::NoActiveAccount + say("You have not set an active account. Use 'twitter change' to set one now.") + rescue Twitter::CLI::Helpers::NoAccounts + say("You have not created any accounts. Use 'twitter add' to create one now.") end end