Skip to content

Commit

Permalink
Merge pull request #8 from skilld-labs/update_deps
Browse files Browse the repository at this point in the history
update deps
  • Loading branch information
davidferlay authored Nov 8, 2024
2 parents 340c03d + 34c10f0 commit 07df196
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.2

require (
github.com/launchrctl/launchr v0.16.4
github.com/skilld-labs/plasmactl-bump/v2 v2.0.4
github.com/skilld-labs/plasmactl-bump/v2 v2.0.7-0.20241101125551-8e6c6264dbc2
github.com/spf13/cobra v1.8.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY=
github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M=
github.com/skilld-labs/plasmactl-bump/v2 v2.0.4 h1:dB4R1NftC8wl5zgvijbFKvFWTb82GPyp43SnXUAWL3Q=
github.com/skilld-labs/plasmactl-bump/v2 v2.0.4/go.mod h1:HgdOmf7bgc3Q38b05RezpADcLGsBvso396tGmQnc4CM=
github.com/skilld-labs/plasmactl-bump/v2 v2.0.7-0.20241101125551-8e6c6264dbc2 h1:iZFtCP4lwwKFc3bOBCcQVGVpT20xYB8Z/IPhm5zF+ts=
github.com/skilld-labs/plasmactl-bump/v2 v2.0.7-0.20241101125551-8e6c6264dbc2/go.mod h1:HgdOmf7bgc3Q38b05RezpADcLGsBvso396tGmQnc4CM=
github.com/sosedoff/ansible-vault-go v0.2.0 h1:XqkBdqbXgTuFQ++NdrZvSdUTNozeb6S3V5x7FVs17vg=
github.com/sosedoff/ansible-vault-go v0.2.0/go.mod h1:wMU54HNJfY0n0KIgbpA9m15NBfaUDlJrAsaZp0FwzkI=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
Expand Down
35 changes: 4 additions & 31 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,22 @@ func dependencies(target, source string, toPath, showTree bool, depth int8) erro
if err != nil {
return err
}
requiredMap := inv.GetRequiredMap()
parents := lookupDependencies(searchMrn, requiredMap, depth)
parents := inv.GetRequiredByResources(searchMrn, depth)
if len(parents) > 0 {
launchr.Term().Info().Println("Dependent resources:")
if showTree {
var parentsTree forwardTree = requiredMap
var parentsTree forwardTree = inv.GetRequiredByMap()
parentsTree.print(header, "", 1, depth, searchMrn, toPath)
} else {
printList(parents, toPath)
}
}

dependenciesMap := inv.GetDependenciesMap()
children := lookupDependencies(searchMrn, dependenciesMap, depth)
children := inv.GetDependsOnResources(searchMrn, depth)
if len(children) > 0 {
launchr.Term().Info().Println("Dependencies:")
if showTree {
var childrenTree forwardTree = dependenciesMap
var childrenTree forwardTree = inv.GetDependsOnMap()
childrenTree.print(header, "", 1, depth, searchMrn, toPath)
} else {
printList(children, toPath)
Expand All @@ -167,31 +165,6 @@ func printList(items map[string]bool, toPath bool) {
}
}

func lookupDependencies(resourceName string, resourcesMap map[string]*sync.OrderedMap[bool], depth int8) map[string]bool {
result := make(map[string]bool)
if m, ok := resourcesMap[resourceName]; ok {
for _, item := range m.Keys() {
result[item] = true
lookupDependenciesRecursively(item, resourcesMap, result, 1, depth)
}
}

return result
}

func lookupDependenciesRecursively(resourceName string, resourcesMap map[string]*sync.OrderedMap[bool], result map[string]bool, depth, limit int8) {
if depth == limit {
return
}

if m, ok := resourcesMap[resourceName]; ok {
for _, item := range m.Keys() {
result[item] = true
lookupDependenciesRecursively(item, resourcesMap, result, depth+1, limit)
}
}
}

type forwardTree map[string]*sync.OrderedMap[bool]

func (t forwardTree) print(header, indent string, depth, limit int8, parent string, toPath bool) {
Expand Down

0 comments on commit 07df196

Please sign in to comment.