Class: HubMerge::Options

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

Class Method Summary collapse

Class Method Details

.allObject



5
6
7
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
33
34
35
36
37
38
39
40
41
42
# File 'lib/hubmerge/options.rb', line 5

def self.all
  {
    repo: {
      short_switch: "-r",
      long_switch: "--repo ORG/REPONAME",
      type: String,
      description: "Github repository to search for PRs in (example: rails/rails)",
    },

    query: {
      short_switch: "-q",
      long_switch: "--query ORG/REPONAME",
      type: String,
      description: "GitHub search query to run to find PRs (example: 'author:app/dependabot')",
    },

    merge_without_confirmation: {
      short_switch: "-y",
      long_switch: "--yes",
      type: :flag,
      description: "Merge without confirmation from user (default: false)"
    },

    approve_before_merge: {
      short_switch: "-a",
      long_switch: "--approve",
      type: :flag,
      description: "Approve PR before merge (default: false)"
    },

    show_version: {
      short_switch: "-v",
      long_switch: "--version",
      type: :flag,
      description: "Show a version and exit (default: false)"
    },
  }
end

.parse(argv) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hubmerge/options.rb', line 44

def self.parse(argv)
  parsed = {}
  opt_parser = OptionParser.new

  all.each do |key, params|
    if params[:type] == :flag
      opt_parser.on(
        params[:short_switch],
        params[:long_switch],
        params[:description]
      ) { |v| parsed[key] = v }
    else
      opt_parser.on(
        params[:short_switch],
        params[:long_switch],
        params[:type],
        params[:description]
      ) { |v| parsed[key] = v }
    end
  end

  opt_parser.parse(argv)
  parsed
end