Skip to content

Commit

Permalink
Made error messages for no accounts and no active account work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jul 26, 2008
1 parent 71091f9 commit dbc9e57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 9 additions & 2 deletions lib/twitter/cli/helpers.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit dbc9e57

Please sign in to comment.