Class: YARD::CLI::Command Abstract

Inherits:
Object
  • Object
show all
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

Since:

  • 0.6.0

Direct Known Subclasses

Config, Diff, Gems, Graph, Help, List, Server, YRI, Yardoc

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(*args) ⇒ Object

Helper method to run the utility on an instance.

See Also:

  • #run

Since:

  • 0.6.0



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

Parameters:

  • opts (OptionParser)

    the option parser object

Since:

  • 0.6.0



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 common_options(opts)
  opts.separator ""
  opts.separator "Other options:"
  opts.on('-e', '--load FILE', 'A Ruby script to load before running command.') do |file|
    load_script(file)
  end
  opts.on('--plugin PLUGIN', 'Load a YARD plugin (gem with `yard-\' prefix)') do |name|
    # Not actually necessary to load here, this is done at boot in YARD::Config.load_plugins
    # YARD::Config.load_plugin(name)
  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

#descriptionObject

Since:

  • 0.6.0



15
# File 'lib/yard/cli/command.rb', line 15

def description; '' end

#load_script(file) ⇒ Object (protected)

Loads a Ruby script. If Config.options[:safe_mode] is enabled, this method will do nothing.

Parameters:

  • file (String)

    the path to the script to load

Since:

  • 0.6.2



64
65
66
67
68
69
70
# File 'lib/yard/cli/command.rb', line 64

def load_script(file)
  return if YARD::Config.options[:safe_mode]
  require(file.gsub(/\.rb$/, ''))
rescue LoadError => load_exception
  log.error "The file `#{file}' could not be loaded:\n#{load_exception}"
  exit
end

#parse_options(opts, args) ⇒ void (protected)

This method returns an undefined value.

Parses the option and gracefully handles invalid switches

Parameters:

  • opts (OptionParser)

    the option parser object

  • args (Array<String>)

    the arguments passed from input. This array will be modified.

Since:

  • 0.6.0



51
52
53
54
55
56
57
# File 'lib/yard/cli/command.rb', line 51

def parse_options(opts, args)
  opts.parse!(args)
rescue OptionParser::ParseError => err
  log.warn "Unrecognized/#{err.message}"
  args.shift if args.first && args.first[0,1] != '-'
  retry
end