Class: Brigit::MapCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/brigit/commands/map_command.rb

Instance Attribute Summary

Attributes inherited from Command

#args

Instance Method Summary collapse

Methods inherited from Command

help, #initialize

Methods included from Pretending

#pretend!

Methods included from Fallible

#fail

Methods included from Listable

included

Constructor Details

This class inherits a constructor from Brigit::Command

Instance Method Details

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/brigit/commands/map_command.rb', line 8

def run
  open = false
  super do |parser|
    parser.on('-o', '--open', "Open as PNG in Preview.app (OSX only, requires `dot')") do
      open = true
    end
  end
  text =  %|digraph G {\n|
  # TODO: Allow customization
  text << %|ranksep=.75; size = "12,12";\n|
  base = Dir.pwd
  Brigit.at_dot_gitmodules do |path|
    origin = origin_at(path)
    text << %|  "#{origin}" [shape="box",style=filled,fillcolor=lightgrey];\n|
    submodules_at(path).each do |submodule|
      text << %| "#{origin}" -> "#{submodule['url']}" [fontsize=16,label="#{submodule['path']}"];\n|
    end
  end
  text << %|}\n|
  if open
    IO.popen("dot -Tpng | open -f -a /Applications/Preview.app", 'w') do |file|
      file.write text
    end
  else
    puts text
  end
end