Class: YourKarma::CLI::ArgumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/yourkarma/cli.rb

Defined Under Namespace

Classes: InvalidOption

Constant Summary collapse

DEFAULT_OPTIONS =
{
  verbose: false,
  poll:    true,
  tail:    false
}

Instance Method Summary collapse

Instance Method Details

#parse(arguments) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/yourkarma/cli.rb', line 178

def parse(arguments)
  options = DEFAULT_OPTIONS.dup
  optparse = OptionParser.new do |opts|
    opts.banner = "      Karma hotspot status\n      Usage: yourkarma [options]\n      Example: yourkarma --verbose\n    BANNER\n\n    opts.on('-u', '--url=URL', \"Karma hotspot URL\") do |url|\n      options[:url] = url\n    end\n    opts.on('-t', '--timeout=TIMEOUT', \"Time to wait for HTTP response\", Float) do |timeout|\n      options[:timeout] = timeout\n    end\n    opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|\n      options[:verbose] = true\n    end\n    opts.on('-c', '--count=COUNT', 'Poll COUNT times', Integer) do |c|\n      options[:iterations] = c\n    end\n    opts.on('-p', '--[no-]poll', 'Continually poll') do |p|\n      options[:poll] = p\n      options[:iterations] = 1 unless p\n    end\n    opts.on('--[no-]tail', 'Tail log') do |t|\n      options[:tail] = t\n    end\n    opts.on('-h', '--help', 'Display this screen') do\n      raise InvalidOption, opts\n    end\n  end\n\n  optparse.parse!(arguments)\n\n  options\nrescue OptionParser::InvalidOption, OptionParser::MissingArgument\n  raise InvalidOption, optparse\nend\n".gsub(/^\s{4}/, '')