Class: YARD::CLI::Command Abstract
- Inherits:
-
Object
- Object
- YARD::CLI::Command
- Defined in:
- lib/yard/cli/command.rb
Overview
This class is abstract.
Abstract base class for CLI utilities. Provides some helper methods for the option parser
Class Method Summary collapse
-
.run(*args) ⇒ Object
Helper method to run the utility on an instance.
Instance Method Summary collapse
-
#common_options(opts) ⇒ void
protected
Adds a set of common options to the tail of the OptionParser.
- #description ⇒ Object
-
#parse_options(opts, args) ⇒ void
protected
Parses the option and gracefully handles invalid switches.
Class Method Details
.run(*args) ⇒ Object
Helper method to run the utility on an instance.
13 |
# File 'lib/yard/cli/command.rb', line 13 def self.run(*args) new.run(*args) end |
Instance Method Details
#common_options(opts) ⇒ void (protected)
This method returns an undefined value.
Adds a set of common options to the tail of the OptionParser
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yard/cli/command.rb', line 23 def (opts) opts.separator "" opts.separator "Other options:" opts.on('-e', '--load FILE', 'A Ruby script to load before the source tree is parsed.') do |file| begin require(file.gsub(/\.rb$/, '')) rescue LoadError log.error "The file `#{file}' could not be loaded, check the path and try again." exit end end opts.on('--legacy', 'Use old style Ruby parser and handlers. Always on in 1.8.x.') do YARD::Parser::SourceParser.parser_type = :ruby18 end opts.on_tail('-q', '--quiet', 'Show no warnings.') { log.level = Logger::ERROR } opts.on_tail('--verbose', 'Show more information.') { log.level = Logger::INFO } opts.on_tail('--debug', 'Show debugging information.') { log.level = Logger::DEBUG } opts.on_tail('--backtrace', 'Show stack traces') { log.show_backtraces = true } opts.on_tail('-v', '--version', 'Show version.') { puts "yard #{YARD::VERSION}"; exit } opts.on_tail('-h', '--help', 'Show this help.') { puts opts; exit } end |
#description ⇒ Object
15 |
# File 'lib/yard/cli/command.rb', line 15 def description; '' end |
#parse_options(opts, args) ⇒ void (protected)
This method returns an undefined value.
Parses the option and gracefully handles invalid switches
51 52 53 54 55 |
# File 'lib/yard/cli/command.rb', line 51 def (opts, args) opts.parse!(args) rescue OptionParser::InvalidOption => e log.warn "Unrecognized/#{e.}" end |