@@ -34,8 +34,8 @@ func printChain(slice []string) {
3434type DependencyOverview struct {
3535 // Dependency graph edges modelled as node plus adjacency nodes
3636 Graph map [string ][]string
37- // List of all (including transitive) dependencies
38- DepList []string
37+ // List of all transitive dependencies
38+ TransDepList []string
3939 // Name of the module from which the dependencies are computed
4040 MainModuleName string
4141}
@@ -53,8 +53,8 @@ func getDepInfo() *DependencyOverview {
5353 depGraph := make (map [string ][]string )
5454 scanner := bufio .NewScanner (strings .NewReader (goModGraphOutputString ))
5555
56- // deps will store all the dependencies
57- var deps []string
56+ // transDeps will store all the transitive dependencies
57+ var transDeps []string
5858 mainModule := "notset"
5959
6060 for scanner .Scan () {
@@ -69,24 +69,21 @@ func getDepInfo() *DependencyOverview {
6969 depGraph [words [0 ]] = append (depGraph [words [0 ]], words [1 ])
7070 }
7171
72- isMainModule := false
7372 if mainModule == "notset" {
7473 mainModule = words [0 ]
75- isMainModule = true
7674 }
7775
78- if ! contains (deps , words [0 ]) && ! isMainModule {
79- // we don't want to add mainModule to deps list
80- deps = append (deps , words [0 ])
76+ // anything where the LHS is not mainModule
77+ // is a transitive dependency
78+ if words [0 ] != mainModule {
79+ if ! contains (transDeps , words [1 ]) {
80+ transDeps = append (transDeps , words [1 ])
81+ }
8182 }
82- if ! contains (deps , words [1 ]) {
83- deps = append (deps , words [1 ])
84- }
85-
8683 }
8784 return & DependencyOverview {
8885 Graph : depGraph ,
89- DepList : deps ,
86+ TransDepList : transDeps ,
9087 MainModuleName : mainModule ,
9188 }
9289}
@@ -100,6 +97,21 @@ func printDeps(deps []string) {
10097 fmt .Println ()
10198}
10299
100+ func getAllDeps (directDeps []string , transDeps []string ) []string {
101+ var allDeps []string
102+ for _ , dep := range directDeps {
103+ if ! contains (allDeps , dep ) {
104+ allDeps = append (allDeps , dep )
105+ }
106+ }
107+ for _ , dep := range transDeps {
108+ if ! contains (allDeps , dep ) {
109+ allDeps = append (allDeps , dep )
110+ }
111+ }
112+ return allDeps
113+ }
114+
103115func contains (s []string , str string ) bool {
104116 for _ , v := range s {
105117 if v == str {
0 commit comments