lib/tw/app/main.rb in tw-0.5.0 vs lib/tw/app/main.rb in tw-0.5.1
- old
+ new
@@ -52,10 +52,11 @@
arg :favorite, 'favorite tweet', :alias => :fav
arg :retweet, 'retweet', :alias => :rt
arg :search, 'search public timeline', :alias => :s
arg :stream, 'show user stream', :alias => :st
arg :status_id, 'show status_id', :alias => :id
+ arg :file, 'upload file'
arg :pipe, 'pipe tweet'
arg :format, 'output format', :default => 'text'
arg :silent, 'silent mode'
arg :conf, 'config file', :default => Tw::Conf.conf_file
arg :version, 'show version', :alias => :v
@@ -70,10 +71,14 @@
end
validate 'dm:to', 'invalid user name' do |v|
v =~ /^[a-zA-Z0-9_]+$/
end
+
+ validate :file, "file does not exists" do |v|
+ File.exists? v
+ end
end
if @parser.has_option? :help
STDERR.puts "Tw - Twitter client on Ruby v#{Tw::VERSION}"
STDERR.puts " http://shokai.github.io/tw"
@@ -81,10 +86,11 @@
STDERR.puts @parser.help
STDERR.puts
STDERR.puts "e.g."
STDERR.puts "tweet tw hello world"
STDERR.puts " echo 'hello' | tw --pipe"
+ STDERR.puts " tw 'yummy!!' --file=food.jpg"
STDERR.puts "read tw @username"
STDERR.puts " tw @username @user2 @user2/listname"
STDERR.puts " tw --search=ruby"
STDERR.puts " tw --stream"
STDERR.puts " tw --stream:filter=ruby,java"
@@ -138,15 +144,22 @@
puts "--"
puts "reply \"#{message}\"? (#{len} chars)"
tweet_opts[:in_reply_to_status_id] = @parser[:status_id]
else
puts "tweet \"#{message}\"? (#{len} chars)"
+ if @parser.has_param? :file
+ puts "upload \"#{@parser[:file]}\"? (#{File.size @parser[:file]} bytes)"
+ end
end
puts '[Y/n]'
on_exit if STDIN.gets.strip =~ /^n/i
end
begin
- client.tweet message, tweet_opts
+ if @parser.has_param? :file
+ client.tweet_with_file message, File.open(@parser[:file]), tweet_opts
+ else
+ client.tweet message, tweet_opts
+ end
rescue => e
STDERR.puts e.message
end
end
end