Class: Turbulence::CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/turbulence/command_line_interface.rb

Constant Summary collapse

TURBULENCE_TEMPLATE_PATH =
File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "template")
TEMPLATE_FILES =
['turbulence.html',
                  'highcharts.js',
                  'jquery.min.js',
                  'treemap.html'].map do |filename|
  File.join(TURBULENCE_TEMPLATE_PATH, filename)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CommandLineInterface

Returns a new instance of CommandLineInterface.



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
# File 'lib/turbulence/command_line_interface.rb', line 19

def initialize(argv)
  Turbulence::Calculators::Churn.scm = Scm::Git
  OptionParser.new do |opts|
    opts.banner = "Usage: bule [options] [dir]"

    opts.on('--scm p4|git', String, 'scm to use (default: git)') do |s|
      case s
      when "git", "", nil
      when "p4"
        Turbulence::Calculators::Churn.scm = Scm::Perforce
      end
    end

    opts.on('--churn-range since..until', String, 'commit range to compute file churn') do |s|
      Turbulence::Calculators::Churn.commit_range = s
    end

    opts.on('--churn-mean', 'calculate mean churn instead of cummulative') do
      Turbulence::Calculators::Churn.compute_mean = true
    end

    opts.on('--exclude pattern', String, 'exclude files matching pattern') do |pattern|
      @exclusion_pattern = pattern
    end

    opts.on('--treemap', String, 'output treemap graph instead of scatterplot') do |s|
      @graph_type = "treemap"
    end


    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end.parse!(argv)

  @directory = argv.first || Dir.pwd
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



18
19
20
# File 'lib/turbulence/command_line_interface.rb', line 18

def directory
  @directory
end

#exclusion_patternObject (readonly)

Returns the value of attribute exclusion_pattern.



17
18
19
# File 'lib/turbulence/command_line_interface.rb', line 17

def exclusion_pattern
  @exclusion_pattern
end

Instance Method Details

#copy_templates_into(directory) ⇒ Object



58
59
60
# File 'lib/turbulence/command_line_interface.rb', line 58

def copy_templates_into(directory)
  FileUtils.cp TEMPLATE_FILES, directory
end

#generate_bundleObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/turbulence/command_line_interface.rb', line 62

def generate_bundle
  FileUtils.mkdir_p("turbulence")

  Dir.chdir("turbulence") do
    turb = Turbulence.new(directory,STDOUT, @exclusion_pattern)

    generator = case @graph_type
    when "treemap"
      Turbulence::Generators::TreeMap.new({})
    else
      Turbulence::Generators::ScatterPlot.new({})
    end

    generator.generate_results(turb.metrics, self)
  end
end

#open_bundleObject



79
80
81
82
83
84
85
86
# File 'lib/turbulence/command_line_interface.rb', line 79

def open_bundle
  case @graph_type
  when "treemap"
    Launchy.open("file://#{directory}/turbulence/treemap.html")
  else
    Launchy.open("file://#{directory}/turbulence/turbulence.html")
  end
end