Class: Gerrit::Cli::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gerrit/cli/command/base.rb

Direct Known Subclasses

Clone, Help, Push

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
# File 'lib/gerrit/cli/command/base.rb', line 15

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

  setup_option_parser
end

Instance Attribute Details

#option_parserObject (readonly)

Returns the value of attribute option_parser.



13
14
15
# File 'lib/gerrit/cli/command/base.rb', line 13

def option_parser
  @option_parser
end

Instance Method Details

#nameObject



37
38
39
# File 'lib/gerrit/cli/command/base.rb', line 37

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

#run(argv) ⇒ Object

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/gerrit/cli/command/base.rb', line 33

def run(argv)
  raise NotImplementedError
end

#setup_option_parserObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/gerrit/cli/command/base.rb', line 22

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

#show_usageObject



49
50
51
# File 'lib/gerrit/cli/command/base.rb', line 49

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

#summaryObject



41
42
43
# File 'lib/gerrit/cli/command/base.rb', line 41

def summary
  @option_parser.banner
end

#usageObject



45
46
47
# File 'lib/gerrit/cli/command/base.rb', line 45

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