'
].join
end
end
def clidoc
puts <<-CLIDOC
#{$PROGRAM_NAME} [OPTION]
-h, --help:
show help
-d, --debug [level]:
Debug level.
-p, --path [location of repo to check]
Path to a location of the repo to check.
Default '.' (Current directory)
If this ends in '/' the script will loop over
all subdirectories. These should all be git repos.
-o, --output [txt|raw|html|yaml|json|...].
Multiple types specified by comma separated string.
eg : -o txt,html
Default 'txt'
-a, --ahead_behind
Show how many commits current commit is ahead or behind remote.
--puppet
Report puppet module info from metadata.json
-t, --tests
Run some test code...
CLIDOC
end
opts = GetoptLong.new(
['--help', '-h', GetoptLong::NO_ARGUMENT],
['--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT],
['--path', '-p', GetoptLong::REQUIRED_ARGUMENT],
['--output', '-o', GetoptLong::REQUIRED_ARGUMENT],
['--ahead_behind', '-a', GetoptLong::NO_ARGUMENT],
['--puppet', GetoptLong::NO_ARGUMENT],
['--test', '-t', GetoptLong::NO_ARGUMENT]
)
debug = 0
path = '.'
output = ['txt']
ahead_behind = false
puppet = false
test = false
opts.each do |opt, arg|
case opt
when '--help'
clidoc
exit
when '--debug'
debug = if arg == ''
1
else
arg.to_i
end
when '--path'
path = arg
when '--output'
output = arg.split(',')
when '--ahead_behind'
ahead_behind = true
when '--puppet'
puppet = true
when '--test'
test = true
end
end
OR = output.include?('raw')
OT = output.include?('txt')
OH = output.include?('html')
OY = output.include?('yaml')
OJ = output.include?('json')
paths = if path.end_with? '/'
Dir.glob("#{path}*/")
else
[path]
end
result = {}
def o_t_p(obj, ap_p = false)
return unless OT
if ap_p
ap obj
else
puts obj
end
end
def o_t_r(obj)
return unless OR
ap obj
end
def o_t_h(obj)
return unless OH
html_str = %(
Puppet Module version report
Puppet Module report : #{Time.now}
#{obj.to_html}
)
puts html_str
end
def o_t_y(obj)
return unless OY
puts obj.to_yaml
end
def o_t_j(obj)
return unless OJ
puts obj.to_json
end
paths.each do |path|
o_t_p "Path : #{path}"
r = {}
gitrepo = Gitrepo::Status.new(path: path)
gitrepo.fetch_all
gitrepo.test if test
r = {}
if ahead_behind
a_b = gitrepo.ahead_behind
unless a_b.nil?
a_b.each do |name, data|
r[name] ||= {}
o_t_p "-- Branch : #{name}"
if (data[0]).zero? && (data[1]).zero?
o_t_p ' Branch up to date.'
else
o_t_p " ahead : #{data[0]} commits"
o_t_p " behind : #{data[1]} commits"
end
r[name]['ahead - behind'] = data
end
end
end
if puppet && gitrepo.puppet_module?
diff = gitrepo.puppet_module_info
keys = %w[version dependencies requirements]
unless diff.empty?
diff.each do |name, data|
r[name] ||= {}
r[name]['puppet'] ||= {}
o_t_p "--- metadata difference with branch : #{name} (keys #{keys})"
data.select { |key, _| keys.include?(key) }.each do |k, v|
o_t_p " Key : #{k}"
o_t_p ' Old : '
o_t_p v[0], true
o_t_p ' New : '
o_t_p v[1], true
r[name]['puppet'][k] = { 'Old' => v[0], 'New' => v[1] }
end
end
end
end
result[path] = r
end
o_t_r result
o_t_h result
o_t_y result
o_t_j result
# vim:set fileencoding=utf8 fileformat=undefined filetype=ruby tabstop=2 expandtab: