Module: Tweetwine::CLI
- Defined in:
- lib/tweetwine/cli.rb
Defined Under Namespace
Classes: Command, FollowersCommand, FriendsCommand, HelpCommand, HomeCommand, MentionsCommand, SearchCommand, UpdateCommand, UserCommand, VersionCommand
Constant Summary collapse
- DEFAULT_COMMAND =
:home
- DEFAULT_CONFIG =
{ :colors => :false, :config_file => "#{(ENV['HOME'] || ENV['USERPROFILE'])}/.tweetwine", :env_lookouts => [:http_proxy], :excludes => [:command], :num_tweets => 20, :page => 1, :show_reverse => false, :shorten_urls => {:disable => true}, :username => ENV['USER'] }.freeze
- EXEC_NAME =
'tweetwine'
Class Method Summary collapse
- .commands ⇒ Object
- .config ⇒ Object
- .find_command(name) ⇒ Object
- .global_option_parser ⇒ Object
- .http ⇒ Object
- .oauth ⇒ Object
- .register_command(cmd_class, names) ⇒ Object
- .start(args = ARGV, overriding_default_conf = nil) ⇒ Object
- .twitter ⇒ Object
- .ui ⇒ Object
- .url_shortener ⇒ Object
Class Method Details
.commands ⇒ Object
49 50 51 52 53 54 |
# File 'lib/tweetwine/cli.rb', line 49 def commands @commands ||= { :primaries => {}, :secondaries => {} } end |
.config ⇒ Object
25 26 27 |
# File 'lib/tweetwine/cli.rb', line 25 def config @config ||= read_config end |
.find_command(name) ⇒ Object
61 62 63 64 |
# File 'lib/tweetwine/cli.rb', line 61 def find_command(name) name = name.to_sym commands[:primaries][name] || commands[:secondaries][name] end |
.global_option_parser ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tweetwine/cli.rb', line 66 def global_option_parser @global_option_parser ||= OptionParser.new do |parser, | parser.on '-c', '--colors', 'Enable ANSI colors for output.' do [:colors] = true end parser.on '-f', '--config <file>', String, "Configuration file (default #{DEFAULT_CONFIG[:config_file]})." do |arg| [:config_file] = arg end parser.on '-h', '--help', 'Show this help and exit.' do [:command] = :help end parser.on '--http-proxy <url>', String, 'Enable HTTP(S) proxy.' do |arg| [:http_proxy] = arg end parser.on '--no-colors', 'Disable ANSI colors for output.' do [:colors] = false end parser.on '--no-http-proxy', 'Disable HTTP(S) proxy.' do [:http_proxy] = nil end parser.on '--no-url-shorten', 'Disable URL shortening.' do [:shorten_urls] ||= {} [:shorten_urls][:disable] = true end parser.on '-n', '--num <n>', Integer, "Number of tweets per page (default #{DEFAULT_CONFIG[:num_tweets]})." do |arg| [:num_tweets] = arg end parser.on '-p', '--page <p>', Integer, "Page number for tweets (default #{DEFAULT_CONFIG[:page]})." do |arg| [:page] = arg end parser.on '-r', '--reverse', "Show tweets in reverse order (default #{DEFAULT_CONFIG[:show_reverse]})." do [:show_reverse] = true end parser.on '-u', '--username <user>', String, "User to authenticate (default '#{DEFAULT_CONFIG[:username]}')." do |arg| [:username] = arg end parser.on '-v', '--version', "Show version and exit." do [:command] = :version end end end |
.http ⇒ Object
29 30 31 |
# File 'lib/tweetwine/cli.rb', line 29 def http @http ||= Http::Client.new(config) end |
.oauth ⇒ Object
33 34 35 |
# File 'lib/tweetwine/cli.rb', line 33 def oauth @oauth ||= OAuth.new(config[:oauth_access]) end |
.register_command(cmd_class, names) ⇒ Object
56 57 58 59 |
# File 'lib/tweetwine/cli.rb', line 56 def register_command(cmd_class, names) commands[:primaries][names.first.to_sym] = cmd_class names[1..-1].each { |name| commands[:secondaries][name.to_sym] = cmd_class } end |
.start(args = ARGV, overriding_default_conf = nil) ⇒ Object
20 21 22 23 |
# File 'lib/tweetwine/cli.rb', line 20 def start(args = ARGV, overriding_default_conf = nil) init(args, overriding_default_conf) run(args) end |
.twitter ⇒ Object
37 38 39 |
# File 'lib/tweetwine/cli.rb', line 37 def twitter @twitter ||= Twitter.new(config) end |
.url_shortener ⇒ Object
45 46 47 |
# File 'lib/tweetwine/cli.rb', line 45 def url_shortener @url_shorterer ||= UrlShortener.new(config[:shorten_urls]) end |