Class: Gerrit::Cli::Command::Base
- Inherits:
-
Object
- Object
- Gerrit::Cli::Command::Base
- Defined in:
- lib/gerrit/cli/command/base.rb
Instance Attribute Summary collapse
-
#option_parser ⇒ Object
readonly
Returns the value of attribute option_parser.
Instance Method Summary collapse
-
#initialize(logger) ⇒ Base
constructor
A new instance of Base.
- #name ⇒ Object
- #run(argv) ⇒ Object
- #setup_option_parser ⇒ Object
- #show_usage ⇒ Object
- #summary ⇒ Object
- #usage ⇒ Object
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_parser ⇒ Object (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
#name ⇒ Object
37 38 39 |
# File 'lib/gerrit/cli/command/base.rb', line 37 def name self.class.name.split('::').last.downcase end |
#run(argv) ⇒ Object
33 34 35 |
# File 'lib/gerrit/cli/command/base.rb', line 33 def run(argv) raise NotImplementedError end |
#setup_option_parser ⇒ Object
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_usage ⇒ Object
49 50 51 |
# File 'lib/gerrit/cli/command/base.rb', line 49 def show_usage @logger.info(usage()) end |
#summary ⇒ Object
41 42 43 |
# File 'lib/gerrit/cli/command/base.rb', line 41 def summary @option_parser. end |
#usage ⇒ Object
45 46 47 |
# File 'lib/gerrit/cli/command/base.rb', line 45 def usage "Usage: gerrit #{name} [options]\n\n" + @option_parser.help end |