Support custom output formats for aptly graph. #163

This commit is contained in:
Andrey Smirnov
2015-03-30 20:26:05 +03:00
parent 27da1015af
commit c10645f4f2
+9 -7
View File
@@ -34,9 +34,11 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
tempfile.Close() tempfile.Close()
os.Remove(tempfile.Name()) os.Remove(tempfile.Name())
tempfilename := tempfile.Name() + ".png" output := context.Flags().Lookup("output").Value.String()
command := exec.Command("dot", "-Tpng", "-o"+tempfilename) tempfilename := tempfile.Name() + "." + output
command := exec.Command("dot", "-T"+output, "-o"+tempfilename)
command.Stderr = os.Stderr command.Stderr = os.Stderr
stdin, err := command.StdinPipe() stdin, err := command.StdinPipe()
@@ -64,11 +66,9 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
return err return err
} }
err = exec.Command("open", tempfilename).Run() fmt.Printf("Rendered to %s file: %s, trying to open it...\n", output, tempfilename)
if err != nil {
fmt.Printf("Rendered to PNG file: %s\n", tempfilename) _ = exec.Command("open", tempfilename).Run()
err = nil
}
return err return err
} }
@@ -89,5 +89,7 @@ Example:
`, `,
} }
cmd.Flag.String("output", "png", "reder graph to output kind (png, svg, pdf, etc.)")
return cmd return cmd
} }