#!/usr/bin/env ruby output = `bundle exec chefstyle -a` if !$?.success? puts "pre-commit hook: Tried to run `bundle exec chefstyle -a` to autocleanup errors, but it failed with output:" puts output end detected = /(\d+) offenses detected/.match(output) corrected = /(\d+) offenses corrected/.match(output) # no errors detected by chefstyle exit 0 if detected.nil? # chefstyle found errors if !detected.nil? # get the first result from the capture group that isn't the whole capture num_detected = detected.to_a[1].to_i num_corrected = if corrected.nil? 0 else corrected.to_a[1].to_i end if num_detected == num_corrected puts <