Class: DevTools::PRlist::OptParse

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

Class Method Summary collapse

Class Method Details

.default_optionsObject



6
7
8
9
10
11
# File 'lib/pr_list/options.rb', line 6

def self.default_options
  {
    markdown: false,
    queue:    false
  }
end

.label_valuesObject



50
51
52
# File 'lib/pr_list/options.rb', line 50

def self.label_values
  Options.labels.keys.map { |k| Options.labels[k] }.flatten.compact
end

.parse(argv_opts = [], unit_testing = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pr_list/options.rb', line 19

def self.parse(argv_opts = [], unit_testing = false)
  opt_parse = DevTools::OptParse.new({ name:     IDENT,
                                       version:  VERSION,
                                       defaults: default_options,
                                       testing:  unit_testing })

  parser = opt_parse.parser

  parser.banner = "Usage: #{DevTools::PROGRAM} [OPTIONS]"

  parser.separator ""
  parser.separator "[OPTIONS]"

  parser.on "-m", "--markdown", "Outputs in markdown friendly format" do
    Options.markdown = true
  end

  parser.on "--[no-]queue", "filters PRs into a queue list for QA" do |opt|
    Options.queue = opt
  end

  parser.separator ""
  parser.separator "Common Options:"

  parser.parse!(argv_opts)

  validate_options unless unit_testing

  Options
end

.validate_optionsObject

Raises:

  • (RuntimeError)


13
14
15
16
17
# File 'lib/pr_list/options.rb', line 13

def self.validate_options
  raise RuntimeError, "Missing configuration file" if Options.nil?
  raise RuntimeError, "Missing authentication token" if Options.token.nil?
  raise RuntimeError, "No repositories provided" if Options.repos.empty?
end