#! /usr/bin/ruby require 'getoptlong' require 'proutils/xact/extract' module Xact # # Extract commandline interface. # class Command def self.run new.run end # attr_reader :file, :start, :stop, :repeat, :style # def initialize opts = GetoptLong.new( [ '--help' , GetoptLong::NO_ARGUMENT ], [ '--repeat', '-r' , GetoptLong::NO_ARGUMENT ], [ '--unxml', '-x' , GetoptLong::NO_ARGUMENT ], [ '--style', '-s' , GetoptLong::REQUIRED_ARGUMENT ] ) repeat = nil style = nil unxml = nil opts.each do |opt, arg| case opt when '--help' help exit 0 when '--repeat' repeat = true when '--style' style = arg when '--unxml' unxml = true end end file = ARGV.shift start = ARGV.shift stop = ARGV.shift # if i = argv.index('-h') # handle = argv[i+1].strip # argv[i+1,1] = nil # argv.delete('-h') # else # handle = 'test' # end # # file = argv.pop unless file && File.file?(file) puts "No such file -- '#{file}'." exit 0 end @file = file @start = start @stop = stop @repeat = repeat @style = style @unxml = unxml end # def extractor @extractor ||= Extractor.new(@file, :unxml => @unxml) end # Extract and display. def run r = case style when 'ruby' extractor.extract_ruby_block_comment(start||'test') when 'rubymethod' extractor.extract_ruby_method_comment(start) else if stop extractor.extract_block(start, stop) else extractor.extract_pattern(start) end end text, offset = *r $stdout << text end # # Extract the code. # # def exact # return *@exacto.extract_block(handle) # end # Show help. def help puts "USAGE: xact [options...] [pattern] [end-pattern]" puts " --help This help ionformation." puts " -r --repeat Repeat for every occurance." puts " --style Use built-in style." end end end Xact::Command.run