| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-04 09:47:54 +02:00
										 |  |  | require "json" | 
					
						
							| 
									
										
										
										
											2020-09-01 18:31:09 +02:00
										 |  |  | require "style" | 
					
						
							| 
									
										
										
										
											2019-10-04 09:47:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2018-09-04 08:45:48 +01:00
										 |  |  |   class Cmd | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:07 +02:00
										 |  |  |     # Implementation of the `brew cask style` command. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api private | 
					
						
							| 
									
										
										
										
											2017-05-20 19:08:03 +02:00
										 |  |  |     class Style < AbstractCommand | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |       def self.description | 
					
						
							|  |  |  |         "Checks style of the given <cask> using RuboCop." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def self.parser | 
					
						
							|  |  |  |         super do | 
					
						
							|  |  |  |           switch "--fix", | 
					
						
							|  |  |  |                  description: "Fix style violations automatically using RuboCop's auto-correct feature." | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { void } | 
					
						
							| 
									
										
										
										
											2019-10-04 09:47:54 +02:00
										 |  |  |       def run | 
					
						
							| 
									
										
										
										
											2020-09-01 18:31:09 +02:00
										 |  |  |         success = Homebrew::Style.check_style_and_print( | 
					
						
							|  |  |  |           cask_paths, | 
					
						
							|  |  |  |           fix:     args.fix?, | 
					
						
							|  |  |  |           debug:   args.debug?, | 
					
						
							|  |  |  |           verbose: args.verbose?, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         raise CaskError, "Style check failed." unless success | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def cask_paths | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |         @cask_paths ||= if args.named.empty? | 
					
						
							| 
									
										
										
										
											2020-09-01 18:34:14 +02:00
										 |  |  |           Tap.map(&:cask_dir).select(&:directory?) | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |         elsif args.named.any? { |file| File.exist?(file) } | 
					
						
							|  |  |  |           args.named.map { |path| Pathname(path).expand_path } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:11:33 +02:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-06-13 17:14:01 +02:00
										 |  |  |           casks.map(&:sourcefile_path) | 
					
						
							| 
									
										
										
										
											2016-10-14 20:11:33 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |