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?