Class: Reek::Options

Inherits:
Object show all
Defined in:
lib/reek/options.rb

Constant Summary collapse

CTX_SORT =
'%c %w (%s)'
SMELL_SORT =
'[%s] %c %w'
@@opts =
default_options

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



19
20
21
# File 'lib/reek/options.rb', line 19

def self.[](key)
  @@opts[key]
end

.default_optionsObject



11
12
13
14
15
# File 'lib/reek/options.rb', line 11

def self.default_options
  {
    :format => CTX_SORT
  }
end

.parse(args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/reek/options.rb', line 45

def self.parse(args)
  begin
    @@opts = parse_args(args)
    if args.length > 0
      return Source.from_pathlist(args)
    else
      return Source.from_io($stdin, 'stdin')
    end
  rescue OptionParser::ParseError, SystemCallError => err
    fatal_error(err)
  end
end

.parse_args(args) ⇒ Object



23
24
25
26
27
28
# File 'lib/reek/options.rb', line 23

def self.parse_args(args)
  result = default_options
  parser = OptionParser.new { |opts| set_options(opts, result) }
  parser.parse!(args)
  result
end

.set_options(opts, config) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/reek/options.rb', line 30

def self.set_options(opts, config)
  opts.banner = <<EOB
Usage: #{opts.program_name} [options] files...

If no files are given, Reek reads source code from standard input.
See http://wiki.github.com/kevinrutherford/reek for detailed help.
EOB
  
  opts.separator "\nOptions:"
  set_help_option(opts)
  set_sort_option(config, opts)
  set_version_option(opts)
  set_output_format_option(config, opts)
end