Method: Twtr::Console#parse

Defined in:
lib/twtr/console.rb

#parse(args) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/twtr/console.rb', line 120

def parse(args)
  @params = {}
  args << '-h' if args.empty?
  args.options do |opt|

    opt.on('-v','--version','Show the version number and quit') do |val|
      puts("twtr #{Twtr::VERSION::STRING}")
    end
    
    opt.on('-h','--help','Show this help message and quit.') do |val|
      show_help(opt)
    end

    opt.on('-c','--count=number', 'Display number statuses.') do |val|
      @params.merge!({:count => val})
      @display_count = val.to_i
    end
    
    opt.on('-i','--id=userid','The ID or screen name of the user.') do |val|
      @params.merge!({:id => val})
    end

    opt.on('-m','--message=message','Post message.') do |val|
      @display_count ||= COUNT_WITH_UPDATE
      @params.merge!({:source => "twtrconsole", :status => val.toutf8})
    end

    opt.on('-l','--location=location','Post location.') do |val|
      @params.merge!({:source => "twtrconsole", :location => val.toutf8})
    end

    opt.on('-p', '--page=number',"Gets the 20 next statuses.") do |val|
      @params.merge!({:page => val.to_i})
    end
    
    opt.on('-C', '--config=path/to/configfile',"Use another config. (default: #{CONFIG_FILE})") do |val|
      @configfile = val
    end

    opt.parse!
  end

  return unless args[0]
  @subcommand = parse_subcommand(args.shift)
end