Class: RubyCritic::Cli::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycritic/cli/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



8
9
10
11
# File 'lib/rubycritic/cli/options.rb', line 8

def initialize(argv)
  @argv = argv
  self.parser = OptionParser.new
end

Instance Method Details

#parseObject

rubocop:disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubycritic/cli/options.rb', line 14

def parse
  parser.new do |opts|
    opts.banner = 'Usage: rubycritic [options] [paths]'

    opts.on('-p', '--path [PATH]', 'Set path where report will be saved (tmp/rubycritic by default)') do |path|
      @root = path
    end

    opts.on(
      '-f', '--format [FORMAT]',
      [:html, :json, :console],
      'Report smells in the given format:',
      '  html (default)',
      '  json',
      '  console'
    ) do |format|
      self.format = format
    end

    opts.on('-s', '--minimum-score [MIN_SCORE]', 'Set a minimum score') do |min_score|
      self.minimum_score = Integer(min_score)
    end

    opts.on('-m', '--mode-ci', 'Use CI mode (faster, but only analyses last commit)') do
      self.mode = :ci
    end

    opts.on('--deduplicate-symlinks', 'De-duplicate symlinks based on their final target') do
      self.deduplicate_symlinks = true
    end

    opts.on('--suppress-ratings', 'Suppress letter ratings') do
      self.suppress_ratings = true
    end

    opts.on('--no-browser', 'Do not open html report with browser') do
      self.no_browser = true
    end

    opts.on_tail('-v', '--version', "Show gem's version") do
      self.mode = :version
    end

    opts.on_tail('-h', '--help', 'Show this message') do
      self.mode = :help
    end
  end.parse!(@argv)
  self
end

#to_hObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rubycritic/cli/options.rb', line 64

def to_h
  {
    mode: mode,
    root: root,
    format: format,
    deduplicate_symlinks: deduplicate_symlinks,
    paths: paths,
    suppress_ratings: suppress_ratings,
    help_text: parser.help,
    minimum_score: minimum_score || 0,
    no_browser: no_browser
  }
end