Created
October 6, 2015 14:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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