Class: YourKarma::CLI::ArgumentParser
- Inherits:
-
Object
- Object
- YourKarma::CLI::ArgumentParser
- 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
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 217 |
# File 'lib/yourkarma/cli.rb', line 179 def parse(arguments) = DEFAULT_OPTIONS.dup optparse = OptionParser.new do |opts| opts. = <<-BANNER.gsub(/^\s{4}/, '') Karma hotspot status Usage: yourkarma [options] Example: yourkarma --verbose BANNER opts.on('-u', '--url=URL', "Karma hotspot URL") do |url| [:url] = url end opts.on('-t', '--timeout=TIMEOUT', "Time to wait for HTTP response", Float) do |timeout| [:timeout] = timeout end opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| [:verbose] = true end opts.on('-c', '--count=COUNT', 'Poll COUNT times', Integer) do |c| [:iterations] = c end opts.on('-p', '--[no-]poll', 'Continually poll') do |p| [:poll] = p [:iterations] = 1 unless p end opts.on('--[no-]tail', 'Tail log') do |t| [:tail] = t end opts.on('-h', '--help', 'Display this screen') do raise InvalidOption, opts end end optparse.parse!(arguments) rescue OptionParser::InvalidOption, OptionParser::MissingArgument raise InvalidOption, optparse end |