Sha256: d3c4a47faab73e42d4da637db4b098c12be2d1319cb23e679c7b738d4bab2305

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'optparse'

module Wordlist
  module Runners
    class Runner
      #
      # Creates and runs the runner with the given arguments.
      #
      # @param [Array<String>] args
      #   Arguments to parse.
      #
      def self.run(*args)
        runner = new()
        runner.run(*args)
      end

      #
      # Runs the runner with the given arguments.
      #
      # @param [Array<String>] args
      #   Arguments to run the runner with.
      #
      def run(*args)
        optparse(*args)
      end

      protected

      #
      # Prints the given error message.
      #
      # @param [String] message
      #   The error message to print.
      #
      def print_error(message)
        $stderr.puts "#{$0}: #{message}"
      end

      #
      # Parses the given arguments.
      #
      # @param [Array<String>] args
      #   Arguments to parse.
      #
      # @yield [opts]
      #   If a block is given, it will be passed the option parse to be
      #   configured.
      #
      # @yieldparam [OptionParser] opts
      #   The option parser to be configured.
      #
      def optparse(*args)
        opts = OptionParser.new()

        yield opts if block_given?

        begin
          opts.parse!(args)
        rescue OptionParser::InvalidOption => e
          $stderr.puts e.message
          $stderr.puts opts
          exit -1
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wordlist-0.1.1 lib/wordlist/runners/runner.rb