Skip to content
This repository has been archived by the owner on Dec 31, 2017. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'timurbatyrshin/master'
Browse files Browse the repository at this point in the history
from: #3
  • Loading branch information
alister committed May 20, 2012
2 parents af4f328 + e11c1ea commit 0736161
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ group :development do
#gem "bundler", "> 1.0.0"
gem "jeweler", "~> 1.8.3"
gem "rcov", ">= 0"
gem 'libnotify'
gem "guard", ">= 0"
end
10 changes: 6 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ GEM
specs:
ffi (1.0.11)
git (1.2.5)
guard (1.0.1)
guard (1.0.3)
ffi (>= 0.5.0)
thor (~> 0.14.6)
thor (>= 0.14.6)
jeweler (1.8.3)
bundler (~> 1.0)
git (>= 1.2.5)
rake
rdoc
json (1.6.6)
json (1.7.3)
libnotify (0.7.2)
rake (0.9.2.2)
rcov (1.0.0)
rdoc (3.12)
json (~> 1.4)
thor (0.14.6)
thor (0.15.2)

PLATFORMS
ruby

DEPENDENCIES
guard
jeweler (~> 1.8.3)
libnotify
rcov
1 change: 1 addition & 0 deletions lib/guard-puppet-lint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'guard/puppet-lint'
58 changes: 51 additions & 7 deletions lib/guard/puppet-lint.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
require 'guard'
require 'guard/guard'
require 'guard/watcher'
require 'puppet-lint'

class PuppetLint

attr_reader :messages

def clear_messages
@messages = []
end

def format_message(message)
@messages << (log_format % message)
end
end

module Guard
class Puppetlint < Guard

VERSION = '0.0.1'

def initialize(watchers = [], options = {})
options = { :syntax_check => true }.merge(options)
@linter = PuppetLint.new
super
end

# Calls #run_all if the :all_on_start option is present.
def start
run_all if options[:all_on_start]
Expand All @@ -17,17 +37,41 @@ def run_all
run_on_change(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
end

def prepend_filename(msg, file)
if msg
msg.map {|x| "#{file}: #{x}"}
else
[]
end
end

# Print the result of the command(s), if there are results to be printed.
def run_on_change(res)
puts res if res
end
messages = []
res.each do |file|
file = File.join( options[:watchdir].to_s,file ) if options[:watchdir]

end
if options[:syntax_check]
parser_messages = `puppet parser validate #{file} --color=false`.split("\n")
parser_messages.reject! { |s| s =~ /puppet help parser validate/ }
parser_messages.map! { |s| s.gsub 'err: Could not parse for environment production:', '' }

messages += prepend_filename(parser_messages, file)
end

class Dsl
# Easy method to display a notification
def n(msg, title='', image=nil)
Notifier.notify(msg, :title => title, :image => image)
@linter.file = file
@linter.clear_messages
@linter.run
linter_msg = @linter.messages.reject { |s| !options[:show_warnings] && s =~ /WARNING/ }
messages += prepend_filename(linter_msg, file)
end
if messages.empty?
messages = ["Files are ok:"] + res
image = :success
else
image = :failed
end
Notifier.notify( messages.join("\n"), :title => "Puppet lint", :image => image )
end
end
end
9 changes: 5 additions & 4 deletions lib/guard/puppet-lint/templates/Guardfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Add files and commands to this file, like the example:
# watch(%r{file/path}) { `command(s)` }
#
guard 'puppet-lint' do
watch(/(.*).pp$/) {|m| `echo #{m[0]}; \
puppet-lint #{m[0]} --no-80chars-check --with-filename
puppet parser validate --color true --render-as s #{m[0]} ` }
guard 'puppet-lint', :watchdir => Guard.options[:watchdir],
:show_warnings => false,
:syntax_check => true \
do
watch(/(.*).pp$/)
end

0 comments on commit 0736161

Please sign in to comment.