Class: CompareLinkerCommand::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/compare_linker_command/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



10
11
12
13
14
# File 'lib/compare_linker_command/parser.rb', line 10

def initialize
  @op = OptionParser.new
  @op.program_name = "create_pr_with_compare_linker"
  @op.version = VERSION
end

Class Method Details

.parse(*args) ⇒ Object



6
7
8
# File 'lib/compare_linker_command/parser.rb', line 6

def self.parse(*args)
  self.new.parse(*args)
end

Instance Method Details

#parse(argv) ⇒ Object



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/compare_linker_command/parser.rb', line 16

def parse(argv)
  params = {succeeded: true}

  @op.on("", "--github-access-token TOKEN", "GitHub token for access") do |v|
    params[:token] = v
  end

  @op.on("", "--repo-name NAME", "org/repository for bundle update") do |v|
    params[:repo_name] = v
  end

  @op.on("", "--pr-body-file [FILEPATH]", "file path of description for bundle update PR (default: empty file)") do |v|
    params[:pr_body_file] = v
  end

  @op.on("", "--pr-number [number]", "PR number. When this option is specified, this command runs compare-linker only.") do |v|
    params[:pr_number] = v.to_s.gsub(/^#/, "")
  end

  error_message = ""

  begin
    @op.parse(argv)
  rescue OptionParser::InvalidOption => e
    error_message << e.message
  end

  unless params[:token]
    error_message << "--github-access-token is required. Abort.\n\n"
  end

  unless params[:repo_name]
    error_message << "--repo-name is required. Abort.\n"
  end

  unless error_message.empty?
    $stderr.puts error_message
    $stderr.puts @op

    params[:succeeded] = false
  end

  params
end