In Files
Parent
Methods
Information
Class Index
- Ratch
- Ratch::Batch
- Ratch::CLI
- Ratch::ConfigUtils
- Ratch::Console
- Ratch::EmailUtils
- Ratch::Emailer
- Ratch::FTPUtils
- Ratch::FileList
- Ratch::FileNotFound
- Ratch::Help
- Ratch::POMUtils
- Ratch::RDocUtils
- Ratch::Script
- Ratch::Shell
- Ratch::System
- Ratch::TarUtils
- Ratch::XDGUtils
- Ratch::ZlibUtils
- FileTest
- Hash
- NilClass
- Object
- String
Help
Support class for displaying command help lists.
Public Class Methods
header(file, opts={})
click to toggle source
Scan script for description header.
# File lib/ratch/script/help.rb, line 60 60: def self.header(file, opts={}) 61: #next if FileTest.directory?(file) 62: #next if opts[:exe] and !FileTest.executable?(file) 63: desc = "\n" 64: File.open(file) do |f| 65: line = '' 66: until f.eof? 67: line = f.gets 68: case line 69: when /^(#!|\s*$)/ 70: next 71: when /^\s*#\s?(.*)/ 72: desc << $1.rstrip + "\n" 73: else 74: break 75: end 76: end 77: end 78: desc + "\n" 79: end
list(*dirs)
click to toggle source
# File lib/ratch/script/help.rb, line 7 7: def self.list(*dirs) 8: tasks = script_descriptions(*dirs) 9: tmax = tasks.keys.max{ |a,b| a.size <=> b.size }.size 10: #dmax = dirs.flatten.max{ |a,b| a.size <=> b.size }.size 11: #if dir == '' 12: # max += 4 + 2 13: #else 14: max = tmax + 4 15: #end 16: tasks = tasks.sort_by{|k,v| k } 17: tasks.each do |name, sum| 18: #if dir == '' 19: # cmd = "ratch #{name}" 20: #else 21: cmd = name 22: #end 23: puts "%-#{max}s # %s" % [cmd, sum] 24: end 25: end
script_descriptions(*dirs)
click to toggle source
Scan task scripts for descriptions.
# File lib/ratch/script/help.rb, line 28 28: def self.script_descriptions(*dirs) 29: opts = Hash === dirs.last ? dirs.pop : {} 30: dirs = dirs.flatten 31: help = {} 32: dirs.each do |dir| 33: files = Dir.glob(File.join(dir,'**/*')) 34: files.each do |fname| 35: next if FileTest.directory?(fname) 36: next if opts[:exe] and !FileTest.executable?(fname) 37: desc = '' 38: File.open(fname) do |f| 39: line = '' 40: until f.eof? 41: line = f.gets 42: case line 43: when /^(#!|\s*$)/ 44: next 45: when /^\s*#(.*)/ 46: desc = $1.strip; break 47: else 48: desc = nil; break 49: end 50: end 51: end 52: key = opts[:exe] ? fname : fname.sub(dir+'/', '') 53: help[key] = desc 54: end 55: end 56: help 57: end
Disabled; run with --debug to generate this.