-
Notifications
You must be signed in to change notification settings - Fork 233
/
run-cookstyle
executable file
·71 lines (52 loc) · 1.64 KB
/
run-cookstyle
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
# vim:fileencoding=utf-8
require 'English'
def main(argv = ARGV)
return 1 if argv.empty?
failed = []
cookbook_path = argv.first
cs_args = %W(#{ENV['CS_ARGS']})
cs_tags = ENV['CS_TAGS'] || File.join(cookbook_path, '.cookstyle-tags')
quiet = ENV['QUIET'].nil? ? false : true
cookstyle_exe = ENV['COOKSTYLE_EXE'] || 'cookstyle'
cs_args += File.read(cs_tags).split.map { |t| "--tags #{t.strip}" } if File.exist?(cs_tags)
Dir.glob("#{cookbook_path}/*") do |cookbook|
next unless File.exist?(File.join(cookbook, 'metadata.rb'))
failed << run_cookstyle_for_cookbook(
cookbook: cookbook,
quiet: quiet,
cs_args: cs_args,
cookstyle_exe: cookstyle_exe
)
end
failed.compact!
unless failed.empty?
puts "FAILED:\n#{failed.join(' ')}"
return 1
end
0
end
def run_cookstyle_for_cookbook(cookbook: '', quiet: false, cs_args: '',
cookstyle_exe: 'cookstyle')
return if cookbook.empty?
return unless File.directory?(cookbook)
cookbook_name = File.basename(cookbook)
return if cookbook_name == 'cookbooks'
cookstyle_command = %W(
#{cookstyle_exe}
#{cs_args.join(' ')}
#{cookbook}
).join(' ')
puts "---> #{cookbook_name}: #{cookstyle_command}" unless quiet
output = `#{cookstyle_command} 2>&1`.chomp
output = output.split(/[\r\n]/).map(&:strip).reject(&:empty?).join("\n")
puts output unless output.empty?
if $CHILD_STATUS.success?
puts "---> #{cookbook_name} ✔︎" unless quiet
else
puts "---> #{cookbook_name} ✘" unless quiet
return cookbook_name
end
nil
end
exit(main) if $PROGRAM_NAME == __FILE__