tags:

views:

36

answers:

1

I have the following task I want to do:

  • Design a base algorithm to analyse log files (please, don't question that).
  • Provide some options through OptionParser to allow variations in calling.
  • Extend the base algorithm by some other scripts that use the original ones.

Now the question: What is the best way to expand the functionality and to use and expand the command-line interface?

The implementation currently is:

ana.rb

class PerfAnalyser
  def self.options(args)
    ...
    PerfAnalyser.new(options).analyze
  end
  def analyse
    # Do base analysis here
  end
end
if __FILE__ == $0
  pa= PerfAnalyzer.options(ARGV)
  pa.print_out
end

overview.rb

def overview(args)
  pa = PerfAnalyzer.options(args)
  pa.overview
end
class PerfAnalyzer
  def overview
    ...
  end
end
if __FILE__ == $0
  overview(ARGV)
end

So I am able to call: ruby ana.rb -f log.log -d dump.dmp and ruby overview.rb -f log.log -d dump.dmp

But how could I add to the script overview.rb some options not known to the script ana.rb? So how to allow ruby overview.rb -f log.log -f tree without copying the code for reading the command-line options?

A: 

You might want to check the commander gem.

Marc-André Lafortune
I'm installing commander right now. Just to be sure: how would my current design of the command-line interface change, and how would it be easier to expand? My goal is to use the command-line interface of another file and expand it (without copying it).
mliebelt