lib/tw/app/main.rb in tw-0.1.1 vs lib/tw/app/main.rb in tw-0.2.0

- old
+ new

@@ -1,6 +1,5 @@ - require File.expand_path 'opt_parser', File.dirname(__FILE__) require File.expand_path 'cmds', File.dirname(__FILE__) require File.expand_path 'render', File.dirname(__FILE__) require File.expand_path 'helper', File.dirname(__FILE__) @@ -49,24 +48,39 @@ arg 'user:default', 'set default user' arg :timeline, 'show timeline', :alias => :tl arg :dm, 'show direct messages' arg 'dm:to', 'create direct message' arg :search, 'search public timeline', :alias => :s + arg :stream, 'show user stream', :alias => :st arg :pipe, 'pipe tweet' arg :version, 'show version', :alias => :v arg :help, 'show help', :alias => :h + + validate :user, 'invalid user name' do |v| + v =~ /^[a-zA-Z0-9_]+$/ + end + + validate 'user:default', 'invalid user name' do |v| + v =~ /^[a-zA-Z0-9_]+$/ + end + + validate 'dm:to', 'invalid user name' do |v| + v =~ /^[a-zA-Z0-9_]+$/ + end end if @parser.has_option? :help STDERR.puts @parser.help STDERR.puts STDERR.puts "e.g." STDERR.puts "tweet tw hello world" + STDERR.puts " echo 'hello' | tw --pipe" 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" STDERR.puts " tw --dm:to=username \"hello!\"" - STDERR.puts " echo 'hello' | tw --pipe" on_exit end regist_cmds