Class: GitHealthCheck::Cli::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/git-health-check/cli/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/git-health-check/cli/options.rb', line 8

def initialize(argv)
  @argv = argv
  @options = {
      :threshold => 0.5,
      :limit => 10,
      :repository => Dir.pwd
  }
  @parser = OptionParser.new
  @command_class = GitHealthCheckCommand
  set_parser_options
end

Instance Method Details



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/git-health-check/cli/options.rb', line 20

def banner
  return <<EOB
Usage: ghc [option]

Output metrics for your Git repository.

Examples:
    ghc
    ghc -t 10
    ghc --threshold 0.2
    ghc -l 20
    ghc --threshold 5 --limit 20
    ghc -r projects/my_repo -t 10 -l 30

EOB
end

#parseObject



61
62
63
64
# File 'lib/git-health-check/cli/options.rb', line 61

def parse
  @parser.parse!(@argv)
  @command_class.new(@parser, @options)
end

#set_parser_optionsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/git-health-check/cli/options.rb', line 37

def set_parser_options
  @parser.banner = banner

  @parser.separator 'Options:'

  @parser.on('-v', '--version', 'Displays the gem version') { @command_class = VersionCommand }

  @parser.on('-h', '--help', 'Displays this help message') { @command_class = HelpCommand }

  @parser.on('-t', '--threshold THRESHOLD', Float, 'Specify minimum history threshold in MB (default 0.5)') do |n|
    @options[:threshold] = n
  end

  @parser.on('-l', '--limit LIMIT', Integer, 'Specify working copy results limit (default 10)') do |n|
    @options[:limit] = n
  end

  @parser.on('-r', '--repository REPOSITORY', String,
             'Specify the repository (current directory by default)') do |repo|
    Dir.chdir repo # handles relative directories
    @options[:repository] = Dir.pwd
  end
end