lib/tw/app/main.rb in tw-0.5.1 vs lib/tw/app/main.rb in tw-0.5.2
- old
+ new
@@ -39,11 +39,11 @@
@on_error.call if @on_error
end
end
def run(argv)
- @parser = ArgsParser.parse argv, :style => :equal do
+ @args = ArgsParser.parse argv, :style => :equal do
arg :user, 'user account', :alias => :u
arg 'user:add', 'add user'
arg 'user:list', 'show user list'
arg 'user:default', 'set default user'
arg :timeline, 'show timeline', :alias => :tl
@@ -56,10 +56,11 @@
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 :yes, 'do not show dialogue'
arg :conf, 'config file', :default => Tw::Conf.conf_file
arg :version, 'show version', :alias => :v
arg :help, 'show help', :alias => :h
validate :user, 'invalid user name' do |v|
@@ -77,20 +78,20 @@
validate :file, "file does not exists" do |v|
File.exists? v
end
end
- if @parser.has_option? :help
+ if @args.has_option? :help
STDERR.puts "Tw - Twitter client on Ruby v#{Tw::VERSION}"
STDERR.puts " http://shokai.github.io/tw"
STDERR.puts
- STDERR.puts @parser.help
+ STDERR.puts @args.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 " tw 'yummy!!' --file=food.jpg --yes"
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"
@@ -103,61 +104,63 @@
STDERR.puts " tw --format=json"
STDERR.puts ' tw --format="@#{user} #{text} - http://twitter.com/#{user}/#{id}"'
on_exit
end
- Render.silent = (@parser.has_option? :silent or @parser.has_param? :format)
- Render.show_status_id = @parser[:status_id]
- Tw::Conf.conf_file = @parser[:conf]
+ Render.silent = (@args.has_option? :silent or @args.has_param? :format)
+ Render.show_status_id = @args[:status_id]
+ Tw::Conf.conf_file = @args[:conf]
regist_cmds
cmds.each do |name, cmd|
- next unless @parser[name]
- cmd.call @parser[name], @parser
+ next unless @args[name]
+ cmd.call @args[name], @args
end
auth
- if @parser.argv.size < 1
- if @parser.has_param? :status_id
- client.show_status @parser[:status_id]
+ if @args.argv.size < 1
+ if @args.has_param? :status_id
+ client.show_status @args[:status_id]
else
- Render.display client.mentions, @parser[:format]
+ Render.display client.mentions, @args[:format]
end
- elsif all_requests?(@parser.argv)
- Render.display Parallel.map(@parser.argv, :in_threads => @parser.argv.size){|arg|
+ elsif all_requests?(@args.argv)
+ Render.display Parallel.map(@args.argv, :in_threads => @args.argv.size){|arg|
if user = username?(arg)
res = client.user_timeline user
elsif (user, list = listname?(arg)) != false
res = client.list_timeline(user, list)
end
res
- }, @parser[:format]
+ }, @args[:format]
else
- message = @parser.argv.join(' ')
+ message = @args.argv.join(' ')
tweet_opts = {}
if (len = message.char_length_with_t_co) > 140
STDERR.puts "tweet too long (#{len} chars)"
on_error
else
- if @parser.has_param? :status_id
- client.show_status @parser[:status_id]
+ if @args.has_param? :status_id
+ client.show_status @args[:status_id]
puts "--"
puts "reply \"#{message}\"? (#{len} chars)"
- tweet_opts[:in_reply_to_status_id] = @parser[:status_id]
+ tweet_opts[:in_reply_to_status_id] = @args[:status_id]
else
puts "tweet \"#{message}\"? (#{len} chars)"
- if @parser.has_param? :file
- puts "upload \"#{@parser[:file]}\"? (#{File.size @parser[:file]} bytes)"
+ if @args.has_param? :file
+ puts "upload \"#{@args[:file]}\"? (#{File.size @args[:file]} bytes)"
end
end
- puts '[Y/n]'
- on_exit if STDIN.gets.strip =~ /^n/i
+ unless @args.has_option? :yes
+ puts '[Y/n]'
+ on_exit if STDIN.gets.strip =~ /^n/i
+ end
end
begin
- if @parser.has_param? :file
- client.tweet_with_file message, File.open(@parser[:file]), tweet_opts
+ if @args.has_param? :file
+ client.tweet_with_file message, File.open(@args[:file]), tweet_opts
else
client.tweet message, tweet_opts
end
rescue => e
STDERR.puts e.message
@@ -165,11 +168,11 @@
end
end
private
def auth
- return unless @parser
- client.auth @parser.has_param?(:user) ? @parser[:user] : nil
+ return unless @args
+ client.auth @args.has_param?(:user) ? @args[:user] : nil
end
end
end