#! /usr/bin/ruby1.8 # scan task scripts for descriptions def script_desc( dir ) help = {} files = Dir.glob( File.join( dir, '*' ) ) files.each do |fname| next if FileTest.directory?( fname ) next unless FileTest.executable?( fname ) desc = '' File.open(fname) do |f| line = '' until f.eof? line = f.gets case line when /^(#!|\s*$)/ next when /^\s*#(.*)/ desc = $1.strip; break else desc = nil; break end end end help[File.basename(fname)] = desc end help end def show( dir ) tasks = script_desc( dir ) max = tasks.keys.max{ |a,b| a.size <=> b.size }.size if dir == '' max += 4 + 2 else max += dir.size + 2 end tasks.each do |name, sum| #sum = Sake.help_summary( type ) if dir == '' cmd = "sake #{name}" else cmd = File.join( dir.chomp('/'), name ) end puts "%-#{max}s # %s" % [cmd, sum] end end dir = ARGV[0] || '.' if File.directory?( dir ) show( dir ) else puts "#{dir} is not a directory" end