Sha256: 63e2db279a80325c54f210367e20b857c52b0ec695eb145b66cd81ffadac88ee

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

require 'logger'
require 'optparse'

module Gerrit
  module Cli
    module Command
    end
  end
end

class Gerrit::Cli::Command::Base

  attr_reader :option_parser

  def initialize(logger)
    @logger = logger
    @option_parser = OptionParser.new

    setup_option_parser
  end

  def setup_option_parser
    @option_parser.on('-h', '--help', 'Display usage') do
      show_usage
      exit 0
    end

    @option_parser.on('-v', '--verbose', 'Show debugging information') do
      @logger.level = Logger::DEBUG
    end
  end

  def run(argv)
    raise NotImplementedError
  end

  def name
    self.class.name.split('::').last.downcase
  end

  def summary
    @option_parser.banner
  end

  def usage
    "Usage: gerrit #{name} [options]\n\n" + @option_parser.help
  end

  def show_usage
    @logger.info(usage())
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gerrit-cli-0.0.1 lib/gerrit/cli/command/base.rb