Parent

Class/Module Index [+]

Quicksearch

Reek::Cli::Options

Parses the command line

Public Class Methods

new(argv) click to toggle source
# File lib/reek/cli/command_line.rb, line 17
def initialize(argv)
  @argv = argv
  @parser = OptionParser.new
  @report_class = VerboseReport
  @command_class = ReekCommand
  @config_files = []
  set_options
end

Public Instance Methods

get_sources() click to toggle source
# File lib/reek/cli/command_line.rb, line 99
def get_sources
  if @argv.empty?
    return [$stdin.to_reek_source('$stdin')]
  else
    return Source::SourceLocator.new(@argv).all_sources
  end
end
parse() click to toggle source
# File lib/reek/cli/command_line.rb, line 84
def parse
  @parser.parse!(@argv)
  if @command_class == HelpCommand
    HelpCommand.new(@parser)
  elsif @command_class == VersionCommand
    VersionCommand.new(@parser.program_name)
  elsif @command_class == YamlCommand
    sources = get_sources
    YamlCommand.create(sources, @config_files)
  else
    sources = get_sources
    ReekCommand.create(sources, @report_class, @config_files)
  end
end
set_options() click to toggle source
# File lib/reek/cli/command_line.rb, line 57
def set_options
  @parser.banner = banner
  @parser.separator "Common options:"
  @parser.on("-h", "--help", "Show this message") do
    @command_class = HelpCommand
  end
  @parser.on("-v", "--version", "Show version") do
    @command_class = VersionCommand
  end

  @parser.separator "\nConfiguration:"
  @parser.on("-c", "--config FILE", "Read configuration options from FILE") do |file|
    @config_files << file
  end

  @parser.separator "\nReport formatting:"
  @parser.on("-q", "--[no-]quiet", "Suppress headings for smell-free source files") do |opt|
    @report_class = opt ? QuietReport : VerboseReport
  end
  @parser.on("-y", "--yaml", "Report smells in YAML format") do
    @command_class = YamlCommand
    # SMELL: the args passed to the command should be tested, because it may
    # turn out that they are passed too soon, ie. before the files have been
    # separated out from the options
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.