(cmd *commander.Command, args []string)
| 16 | ) |
| 17 | |
| 18 | func aptlyGraph(cmd *commander.Command, args []string) error { |
| 19 | var err error |
| 20 | |
| 21 | if len(args) != 0 { |
| 22 | cmd.Usage() |
| 23 | return commander.ErrCommandError |
| 24 | } |
| 25 | |
| 26 | layout := context.Flags().Lookup("layout").Value.String() |
| 27 | |
| 28 | fmt.Printf("Generating graph...\n") |
| 29 | collectionFactory := context.NewCollectionFactory() |
| 30 | graph, err := deb.BuildGraph(collectionFactory, layout) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | buf := bytes.NewBufferString(graph.String()) |
| 36 | |
| 37 | tempfile, err := os.CreateTemp("", "aptly-graph") |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | _ = tempfile.Close() |
| 42 | _ = os.Remove(tempfile.Name()) |
| 43 | |
| 44 | format := context.Flags().Lookup("format").Value.String() |
| 45 | output := context.Flags().Lookup("output").Value.String() |
| 46 | |
| 47 | if filepath.Ext(output) != "" { |
| 48 | format = filepath.Ext(output)[1:] |
| 49 | } |
| 50 | |
| 51 | tempfilename := tempfile.Name() + "." + format |
| 52 | |
| 53 | command := exec.Command("dot", "-T"+format, "-o"+tempfilename) |
| 54 | command.Stderr = os.Stderr |
| 55 | |
| 56 | stdin, err := command.StdinPipe() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | err = command.Start() |
| 62 | if err != nil { |
| 63 | return fmt.Errorf("unable to execute dot: %s (is graphviz package installed?)", err) |
| 64 | } |
| 65 | |
| 66 | _, err = io.Copy(stdin, buf) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | err = stdin.Close() |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 |
nothing calls this directly
no test coverage detected