class YARD::CLI::YardoptsCommand

Abstract base class for command that reads .yardopts file

@abstract @since 0.8.3

Constants

DEFAULT_YARDOPTS_FILE

The configuration filename to load extra options from

Attributes

options_file[RW]

The options file name (defaults to {DEFAULT_YARDOPTS_FILE}) @return [String] the filename to load extra options from

use_document_file[RW]

@return [Boolean] whether to parse options from .document

use_yardopts_file[RW]

@return [Boolean] whether to parse options from .yardopts

Public Class Methods

new() click to toggle source

Creates a new command that reads .yardopts

Calls superclass method
# File lib/yard/cli/yardopts_command.rb, line 24
def initialize
  super
  @options_file = DEFAULT_YARDOPTS_FILE
  @use_yardopts_file = true
  @use_document_file = true
end

Public Instance Methods

parse_arguments(*args) click to toggle source

Parses commandline arguments @param [Array<String>] args the list of arguments @return [Boolean] whether or not arguments are valid @since 0.5.6

# File lib/yard/cli/yardopts_command.rb, line 35
def parse_arguments(*args)
  parse_yardopts_options(*args)

  # Parse files and then command line arguments
  parse_rdoc_document_file
  parse_yardopts
  optparse(*args)
end

Protected Instance Methods

yardopts_options(opts) click to toggle source

Adds –[no-]yardopts / –[no-]document

# File lib/yard/cli/yardopts_command.rb, line 47
def yardopts_options(opts)
  opts.on('--[no-]yardopts [FILE]',
          "If arguments should be read from FILE",
          "  (defaults to yes, FILE defaults to .yardopts)") do |use_yardopts|
    if use_yardopts.is_a?(String)
      self.options_file = use_yardopts
      self.use_yardopts_file = true
    else
      self.use_yardopts_file = (use_yardopts != false)
    end
  end

  opts.on('--[no-]document', "If arguments should be read from .document file. ",
                             "  (defaults to yes)") do |use_document|
    self.use_document_file = use_document
  end
end

Private Instance Methods

parse_rdoc_document_file(file = '.document') click to toggle source
# File lib/yard/cli/yardopts_command.rb, line 91
def parse_rdoc_document_file(file = '.document')
  optparse(*support_rdoc_document_file!(file)) if use_document_file
end
parse_yardopts(file = options_file) click to toggle source
# File lib/yard/cli/yardopts_command.rb, line 95
def parse_yardopts(file = options_file)
  optparse(*yardopts(file)) if use_yardopts_file
end
parse_yardopts_options(*args) click to toggle source

Parses out the yardopts/document options

# File lib/yard/cli/yardopts_command.rb, line 77
def parse_yardopts_options(*args)
  opts = OptionParser.new
  opts.base.long.clear # HACK: why are --help and --version defined?
  yardopts_options(opts)
  begin
    opts.parse(args)
  rescue OptionParser::ParseError => err
    idx = args.index(err.args.first)
    args = args[(idx+1)..-1]
    args.shift while args.first && args.first[0,1] != '-'
    retry
  end
end
support_rdoc_document_file!(file = '.document') click to toggle source

Reads a .document file in the directory to get source file globs @return [Array<String>] an array of files parsed from .document

# File lib/yard/cli/yardopts_command.rb, line 101
def support_rdoc_document_file!(file = '.document')
  return [] unless use_document_file
  File.read(file).gsub(/^[ \t]*#.+/m, '').split(/\s+/)
rescue Errno::ENOENT
  []
end
yardopts(file = options_file) click to toggle source

Parses the .yardopts file for default yard options @return [Array<String>] an array of options parsed from .yardopts

# File lib/yard/cli/yardopts_command.rb, line 69
def yardopts(file = options_file)
  return [] unless use_yardopts_file
  File.read_binary(file).shell_split
rescue Errno::ENOENT
  []
end