Class: Lcoveralls::OptionParser
- Inherits:
-
Object
- Object
- Lcoveralls::OptionParser
- Defined in:
- lib/lcoveralls/option_parser.rb
Overview
Parses CLI options for the Lcoveralls application.
Instance Method Summary collapse
-
#parse!(args) ⇒ Hash
Destructively parse the command line arguments.
Instance Method Details
#parse!(args) ⇒ Hash
Destructively parse the command line arguments.
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 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 |
# File 'lib/lcoveralls/option_parser.rb', line 30 def parse!(args) = { :color => $stderr.isatty, :git => 'git', :retry_count => 0, :retry_interval => 10.0, :service => File.basename($0), :severity => Logger::INFO } if ENV.has_key? 'TRAVIS_JOB_NUMBER' then [:service] = 'travis-ci' [:job_id] = ENV['TRAVIS_JOB_ID'] end parser = ::OptionParser.new do |o| o. = "Usage: #{o.program_name} [options] [tracefile(s)]" o.summary_width = 30 o.separator '' o.separator 'Code / coveralls.io options:' o.on( '--dryrun', 'Do not submit to coveralls.io' ) { [:dryrun] = true } o.on( '--export [PATH=stdout]', 'Export Coveralls job data') do |path| [:export] = case path when 'stderr'; $stderr when 'stdout'; $stdout when nil ; $stdout else File.new(path, 'w') end end o.on('-r', '--root PATH', 'Set the path to the repo root') { |path| [:root] = File.realpath(path) } o.on('-s', '--service NAME','Set coveralls service name') { |name| [:service] = name } o.on('-t', '--token TOKEN', 'Set coveralls repo token') { |token| [:token] = token } o.separator '' o.separator 'Network options:' o.on('--timeout DURATION', 'Timout, in seconds, for network open and read operations') do |duration| [:timeout] = duration.to_f end o.on('--retry-count COUNT', 'Number of times to retry sending to coveralls.io') do |count| [:retry_count] = count.to_i end o.on('--retry-interval DURATION', 'Time to wait between retries') do |count| [:retry_interval] = count.to_f; end o.separator '' o.separator 'Stderr output options:' o.on( '--[no-]color', 'Colorize output') { |color| [:color] = color } o.on('-d', '--debug', 'Enable debugging') { [:severity] = Logger::DEBUG } o.on( '--trace', 'Maximum output') { [:severity] = Logger::TRACE } o.on('-q', '--quiet', 'Show less output') { [:severity] = [:severity] + 1 } o.on('-v', '--verbose', 'Show more output') { [:severity] = [:severity] - 1 } o.separator '' o.separator 'Miscellaneous options:' o.on( '--[no-]git PATH', 'Path to the git program') { |path| [:git] = path } o.on('-h', '--help', 'Print usage text, then exit') { puts o; exit } o.on( '--version', 'Print version number, then exit') { puts VERSION.join('.'); exit } o.separator '' end begin parser.parse! args rescue ::OptionParser::InvalidOption => e $stderr.puts parser $stderr.puts e exit(false) end end |