Class: TriggerBuild::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/trigger_build/options.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/trigger_build/options.rb', line 8

def self.parse(args)
  opts = Slop.parse(args) do |o|
    o.banner = 'usage: trigger_build [options] owner repo'
    o.separator ''
    o.separator 'options:'
    o.bool '--pro', 'use travis-ci.com'
    o.string '-t', '--token',
      'the Travis CI API token (default: TRAVIS_API_TOKEN)', default: ENV['TRAVIS_API_TOKEN']
    o.on '-h', '--help', 'display this message' do
      puts o
      exit
    end
    o.on '-v', '--version', 'print the version' do
      puts TriggerBuild::VERSION
      exit
    end
  end

  unless opts.arguments.length == 2
    abort opts.to_s
  end

  owner, repo = *opts.args
  { owner: owner, repo: repo, token: opts[:token], pro: opts.pro? }
end