Class: Babygitter::ReportGenerator::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/babygitter/report_generator/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/babygitter/report_generator/options.rb', line 22

def initialize(args)
  super()
 
  @opts = OptionParser.new do |opts|
    opts.banner = "Usage: babygitter #{File.basename($0)}  <Repo_Directory> [options] [-w] [<folder levels>] [<blacklisted or whitelisted folders>]"
  
    opts.separator ""
    opts.separator "Specific options:"

    # Set folder levels to be plotted
    opts.on("-l", "--levels [n1,n2,n3]",
            "Folder levels to map to graph", Array) do |levels|  
      Babygitter.folder_levels  = levels.map {|n| n.to_i}.sort unless levels.nil?
    end

    # Mark folders to be whitelisted or lacklisted
    opts.on("-m", "--mark [f1,f2,f3]",
            "Mark folders to be white or black listed depending on option", Array) do |folders|
      Babygitter.marked_folders  = folders  unless folders.nil?
    end
    
    # Set the name of the master branch
    opts.on("--master_branch",
            "Set the master branch name if it is not called master") do |master_branch|
      self[:master_branch] = master_branch
    end
    
    # Set the stylesheet
    opts.on("-s", "--stylesheet [Path]",
            "sets the path to a custome stylesheet used in the  report generator") do |path|
      expanded_path = File.expand_path path
      check_if_file_exits(expanded_path)
      Babygitter.stylesheet = expanded_path
    end
    
    # Set the stylesheet
    opts.on("-i", "--image_path [Path]",
            "sets the path to a custome image folder to be used in the report generator") do |path|
      expanded_path = File.expand_path path
      check_if_directory_exits(expanded_path)
      Babygitter.image_assets_path = File.expand_path path
    end
    
    # Set a custome template
    opts.on("-t", "--template [Path]",
            "sets the path to a custome template to be used in the report generator") do |path|
      expanded_path = File.expand_path path
      check_if_file_exits(expanded_path)
      Babygitter.template = File.expand_path path
    end
    
    # Boolean switch.
    opts.on("-b", "--[no-]bare", "Mark repo as bare") do |b|
      self[:is_bare] = b
    end

    # Boolean switch.for whitelist
    opts.on("-w", "--[no-]whitelist", "Run babygitter with whitelist enabled") do |w|
      Babygitter.use_whitelist = w
    end

    # Boolean switch for graphs.
    opts.on("-g", "--[yes-]graphs", "Do not output report with graphs") do 
      Babygitter.output_graphs = false
    end
    
    # Boolean switch for application to run verbosely.
    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      self[:verbose] = v
    end

    opts.separator ""
    opts.separator "Common options:"

    # No argument, shows at tail.  This will print an options summary.
    # Try it and see!
    opts.on_tail("-h", "--help", "Show this message") do
      self[:show_help] = true
    end

    # Switch to print the version.
    opts.on_tail("--version", "Show version number") do
      self[:show_version_number] = true
    end
  end
  
  begin
    @opts.parse!(args)
  rescue OptionParser::ParseError => e
    warn e.message
    puts opts
    exit 1
  end
  
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/babygitter/report_generator/options.rb', line 4

def opts
  @opts
end

Instance Method Details

#check_if_directory_exits(path) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/babygitter/report_generator/options.rb', line 6

def check_if_directory_exits(path)
  if !File.exists?(path)
    abort "'#{path}' does not exist."
  elsif !File.directory?(path)
    abort "'#{path}' is not a directory."
  end
end

#check_if_file_exits(path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/babygitter/report_generator/options.rb', line 14

def check_if_file_exits(path)
  if !File.exists?(path)
    abort "'#{path}' does not exist."
  elsif File.directory?(path)
    abort "'#{path}' is a directory."
  end
end