Revision: 2796
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 16, 2007 17:35 by felipec
Initial Code
#!/usr/bin/env ruby
require 'twitter'
require 'optparse'
# UI Application
$options = {}
class App
def initialize(args)
begin
parse_options(args)
rescue ArgumentError, OptionParser::ParseError => msg
$stderr.print "Error: #{msg}\n"
exit
end
end
def parse_options(args)
commands = [:update]
OptionParser.new do |opts|
opts.banner = "Usage: twitter [options]"
opts.on("-c", "--command COMMAND", commands) do |v|
$options[:command] = v
end
opts.on("-m", "--message MESSAGE") do |v|
$options[:message] = v
end
opts.on("-u", "--username USER") do |v|
$options[:username] = v
end
opts.on("-p", "--password PASSWORD") do |v|
$options[:password] = v
end
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
$options[:verbose] = v
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!(args)
case $options[:command]
when :update
raise ArgumentError, "Update needs a message" if not $options[:message]
end
end
def run()
case $options[:command]
when :update
print "update: %s\n" % [$options[:message]]
conn = Twitter::Connection.new($options[:username], $options[:password])
conn.status.update($options[:message])
end
end
end
app = App.new(ARGV)
app.run()
Initial URL
Initial Description
Initial Title
Ruby Twitter CLI
Initial Tags
Initial Language
Ruby