MCPcopy Create free account
hub / github.com/aptly-dev/aptly / aptlyGraph

Function aptlyGraph

cmd/graph.go:18–101  ·  view source on GitHub ↗
(cmd *commander.Command, args []string)

Source from the content-addressed store, hash-verified

16)
17
18func 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

Callers

nothing calls this directly

Calls 12

BuildGraphFunction · 0.92
CopyFileFunction · 0.92
getOpenCommandFunction · 0.85
FlagsMethod · 0.80
NewCollectionFactoryMethod · 0.80
WaitMethod · 0.80
StringMethod · 0.65
PrintfMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65
StartMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected