forked from github/octocatalog-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.rb
50 lines (45 loc) · 1.97 KB
/
parser.rb
1
2
3
4
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
43
44
45
46
47
48
49
50
# frozen_string_literal: true
# Enable future parser for both branches or for just one
# @param parser [OptionParser object] The OptionParser argument
# @param options [Hash] Options hash being constructed; this is modified in this method.
OctocatalogDiff::Cli::Options::Option.newoption(:parser) do
has_weight 270
def parse(parser, options)
supported_parsers = %w(default future)
parser_str = supported_parsers.join(', ')
# --parser sets both parser-to and parser-from
parser.on('--parser PARSER_NAME', "Specify parser (#{parser_str})") do |x|
unless supported_parsers.include?(x)
raise ArgumentError, "--parser must be one of: #{parser_str}"
end
unless options[:parser_from].nil? || options[:parser_from] == x.to_sym
raise ArgumentError, '--parser conflicts with --parser-from'
end
unless options[:parser_to].nil? || options[:parser_to] == x.to_sym
raise ArgumentError, '--parser conflicts with --parser-to'
end
options[:parser_from] = x.to_sym
options[:parser_to] = x.to_sym
end
# --parser-from sets parser for the 'from' branch
parser.on('--parser-from PARSER_NAME', "Specify parser (#{parser_str})") do |x|
unless supported_parsers.include?(x)
raise ArgumentError, "--parser-from must be one of: #{parser_str}"
end
unless options[:parser_from].nil? || options[:parser_from] == x.to_sym
raise ArgumentError, '--parser incompatible with --parser-from'
end
options[:parser_from] = x.to_sym
end
# --parser-to sets parser for the 'to' branch
parser.on('--parser-to PARSER_NAME', "Specify parser (#{parser_str})") do |x|
unless supported_parsers.include?(x)
raise ArgumentError, "--parser-to must be one of: #{parser_str}"
end
unless options[:parser_to].nil? || options[:parser_to] == x.to_sym
raise ArgumentError, '--parser incompatible with --parser-to'
end
options[:parser_to] = x.to_sym
end
end
end