Skip to content

Commit

Permalink
Added #d command line functionality. Also, d now takes stdin for mess…
Browse files Browse the repository at this point in the history
…age.
  • Loading branch information
jnunemaker committed Jul 22, 2008
1 parent ad2da16 commit 25ddfe3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 6 additions & 1 deletion bin/twitter
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/usr/bin/env ruby

# if we have stdin, let's prepend it to the message
# if we have stdin, let's prepend it to the message for post
if ARGV[0] && ARGV[0] == 'post' && !STDIN.tty?
ARGV[1] = "#{STDIN.read}#{ARGV[1]}"
end

# if we have stdin, let's prepend it to the message for d
if ARGV[0] && ARGV[0] == 'd' && !STDIN.tty?
ARGV[2] = "#{STDIN.read}#{ARGV[2]}"
end

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'twitter'
require 'twitter/cli'
23 changes: 17 additions & 6 deletions lib/twitter/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,7 @@ def run
mode 'post' do
def run
do_work do
post = if ARGV.size > 1
ARGV.join " "
else
ARGV.shift
end

post = ARGV.size > 1 ? ARGV.join(" ") : ARGV.shift
say "Sending twitter update"
finished, status = false, nil
progress_thread = Thread.new { until finished; print "."; $stdout.flush; sleep 0.5; end; }
Expand Down Expand Up @@ -187,4 +182,20 @@ def run
end
end
end

mode 'd' do
argument('username') {
required
description 'username or id of twitterrer to direct message'
}

def run
do_work do
username = params['username'].value
post = ARGV.size > 1 ? ARGV.join(" ") : ARGV.shift
base.d(username, post)
say "Direct message sent to #{username}"
end
end
end
}

0 comments on commit 25ddfe3

Please sign in to comment.