Skip to content

Instantly share code, notes, and snippets.

@sozorogami
Created October 6, 2015 14:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sozorogami/402b62d95a11fe05562f to your computer and use it in GitHub Desktop.
Save sozorogami/402b62d95a11fe05562f to your computer and use it in GitHub Desktop.
Convert `Podfile.lock` dependency list into a `.dot` file than can be opened in OmniGraffle
package main
import "os"
import "bufio"
import "io/ioutil"
import "regexp"
import "strings"
// Copy Podfile.lock contents into input.txt in same dir as script
// Output is in output.dot
func main() {
file, err := os.Open("input.txt")
if err != nil {
panic(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
var currentPod = ""
var currentDependency = ""
var output = "digraph G {\n\tnode [shape=box];\n"
for scanner.Scan() {
line := scanner.Text()
if !strings.Contains(line, "PODS") && !strings.Contains(line, " ") {
break
}
if strings.HasPrefix(line, " -") {
currentDependency = quote(stripToName(line))
}
if currentPod != "" {
var connection string
if currentDependency != "" {
connection = currentPod + " -> " + currentDependency
} else {
connection = currentPod + " -> {}"
}
output = "\t" + output + connection + ";\n"
currentDependency = ""
}
if strings.HasPrefix(line, " -") {
currentPod = quote(stripToName(line))
currentDependency = ""
}
}
output = output + "}\n"
ioutil.WriteFile("output.dot", []byte(output), 0644)
}
func quote(s string) string {
return "\"" + s + "\""
}
func stripToName(s string) string {
r := regexp.MustCompile("- ([^ ]+)")
return r.FindStringSubmatch(s)[1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment