| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 19:42:27 +09:00
										 |  |  | require "ostruct" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							|  |  |  |   module CLI | 
					
						
							|  |  |  |     class Args < OpenStruct | 
					
						
							| 
									
										
										
										
											2019-09-22 20:13:11 +05:30
										 |  |  |       attr_accessor :processed_options | 
					
						
							| 
									
										
										
										
											2019-04-17 19:42:27 +09:00
										 |  |  |       # undefine tap to allow --tap argument | 
					
						
							|  |  |  |       undef tap | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def initialize(argv:) | 
					
						
							|  |  |  |         super | 
					
						
							|  |  |  |         @argv = argv | 
					
						
							| 
									
										
										
										
											2019-09-22 20:13:11 +05:30
										 |  |  |         @processed_options = [] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def option_to_name(option) | 
					
						
							|  |  |  |         option.sub(/\A--?/, "") | 
					
						
							|  |  |  |               .tr("-", "_") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def cli_args | 
					
						
							| 
									
										
										
										
											2019-09-25 14:21:06 +05:30
										 |  |  |         return @cli_args if @cli_args | 
					
						
							| 
									
										
										
										
											2019-09-22 20:13:11 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         @cli_args = [] | 
					
						
							|  |  |  |         processed_options.each do |short, long| | 
					
						
							|  |  |  |           option = long || short | 
					
						
							|  |  |  |           switch = "#{option_to_name(option)}?".to_sym | 
					
						
							|  |  |  |           flag = option_to_name(option).to_sym | 
					
						
							| 
									
										
										
										
											2019-09-25 14:21:06 +05:30
										 |  |  |           if @table[switch] == true || @table[flag] == true | 
					
						
							| 
									
										
										
										
											2019-09-22 20:13:11 +05:30
										 |  |  |             @cli_args << option | 
					
						
							|  |  |  |           elsif @table[flag].instance_of? String | 
					
						
							|  |  |  |             @cli_args << option + "=" + @table[flag] | 
					
						
							|  |  |  |           elsif @table[flag].instance_of? Array | 
					
						
							|  |  |  |             @cli_args << option + "=" + @table[flag].join(",") | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         @cli_args | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def options_only | 
					
						
							|  |  |  |         @options_only ||= cli_args.select { |arg| arg.start_with?("-") } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def flags_only | 
					
						
							|  |  |  |         @flags_only ||= cli_args.select { |arg| arg.start_with?("--") } | 
					
						
							| 
									
										
										
										
											2019-04-17 19:42:27 +09:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-09-25 14:21:06 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |       def passthrough | 
					
						
							|  |  |  |         options_only - CLI::Parser.global_options.values.map(&:first).flatten | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2019-04-17 19:42:27 +09:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |