Class: GitPissed::Options

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

Constant Summary collapse

MAX_REVISIONS =
30
DEFAULT_WORDS =
%w(
  shit
  fuck
  crap
).freeze
FORMATS =
%w(
  html
  csv
).freeze

Instance Method Summary collapse

Instance Method Details

#formatObject



24
25
26
# File 'lib/git_pissed/options.rb', line 24

def format
  @format ||= FORMATS.first
end

#max_revisionsObject



20
21
22
# File 'lib/git_pissed/options.rb', line 20

def max_revisions
  @max_revisions ||= MAX_REVISIONS
end

#parse!Object



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
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/git_pissed/options.rb', line 28

def parse!
  options = OptionParser.new do |opts|
    opts.banner = [
      'usage: git-pissed',
      '[--words=<array>]',
      '[--max-revisions=<integer>]',
      "[--format=<#{FORMATS.join('|')}>]",
      '[--version]'
    ].join(' ')

    opts.separator "\noptions:"

    opts.on(
      "--words=#{DEFAULT_WORDS.join(',')}", Array,
      'Words to track across entire history'
    ) do |words|
      raise OptionParser::InvalidArgument if words.empty?
      @words = words
    end

    opts.on(
      "--max-revisions=#{MAX_REVISIONS}", Integer,
      'Number of revisions to track, spread equally across entire history'
    ) do |max_revisions|
      @max_revisions = max_revisions
    end

    opts.on(
      "--format=#{FORMATS.first}", String,
      "Output format. Supported formats: #{FORMATS.join(', ')}"
    ) do |format|
      raise OptionParser::InvalidArgument unless FORMATS.include?(format)
      @format = format
    end

    opts.on('--version', 'Show version') do
      puts VERSION
      exit
    end
  end

  options.parse!

  self
rescue OptionParser::MissingArgument, OptionParser::InvalidArgument
  abort options.help
end

#wordsObject



16
17
18
# File 'lib/git_pissed/options.rb', line 16

def words
  @words ||= DEFAULT_WORDS
end