15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/twat/argparse.rb', line 15
def getopts
options = Hash.new
options[:action] = :tweet
options[:count] = 1
@optparser = OptionParser.new do |opts|
opts.banner = "Usage: twat <tweet>"
opts.on('-n', '--account ACCOUNT', 'Use ACCOUNT (or default)') do |acct| options[:account] = acct.to_sym
end opts.on('-a', '--add ACCOUNT', 'Configure and authorise ACCOUNT') do |acct| options[:account] = acct.to_sym
options[:action] = :add
end opts.on('-d', '--delete ACCOUNT', 'Delete ACCOUNT') do |acct| options[:account] = acct.to_sym
options[:action] = :delete
end opts.on('-h', '--help', 'Display this screen') do puts opts
exit
end opts.on('-l', '--list [COUNT]', 'Display [count] tweets from your newsfeed') do |count| options[:count] = count || 10
options[:action] ||= :show
end opts.on('-f', '--follow', 'Display tweets from your newsfeed indefinitely') do options[:action] = :follow
end opts.on('-v', '--version', 'Display version info') do options[:action] = :version
end opts.on('-u', '--user [USER]', 'Display current status for USER (Defaults to your default account)') do |user| options[:user] = (user || :default)
options[:action] = :user_feed
end opts.on("--set OPTION=VALUE", 'Set OPTION to VALUE') do |optval| options[:action] = :setoption
options[:optval] = optval
end opts.on("--update-config", "Update config to latest version") do options[:action] = :updateconfig
end end
@optparser.parse!
REQUIRED.each do |req|
usage unless options[req]
end
if MSG_REQUIRED.include?(options[:action])
options[:msg] = msg
end
options
end
|