class DuoSplitter::Runner
Public Class Methods
known_commands()
click to toggle source
# File lib/duo_splitter/runner.rb, line 8 def known_commands @known_commands ||= {} end
new(argv)
click to toggle source
# File lib/duo_splitter/runner.rb, line 17 def initialize(argv) @argv = argv.dup @parser = OptionParser.new parse_options end
register_command(command_name, command_class)
click to toggle source
# File lib/duo_splitter/runner.rb, line 12 def register_command(command_name, command_class) known_commands[command_name.to_sym] = command_class end
Public Instance Methods
run()
click to toggle source
# File lib/duo_splitter/runner.rb, line 24 def run command_name = @argv.shift if command_name command_class = self.class.known_commands[command_name.to_sym] raise Error, "unknown command: #{command_name}" unless command_class command_class.new(@argv).run else show_help end end
Private Instance Methods
parse_options()
click to toggle source
# File lib/duo_splitter/runner.rb, line 40 def parse_options @parser.banner = "Usage: #{@parser.program_name} [options] command" @parser.on('-h', '--help', 'Print this message') do show_help exit end @parser.on('-v', '--version', 'Print version number') do puts DuoSplitter::VERSION exit end begin @parser.order!(@argv) rescue OptionParser::ParseError => e raise Error, e.message end end
show_help()
click to toggle source
# File lib/duo_splitter/runner.rb, line 60 def show_help puts @parser puts puts <<~MESSAGE Available commands are: - split - repeating - overlapping MESSAGE end