Add "--uniq" to "parents"/"children" (and have it actually do the right thing)
This commit is contained in:
parent
7c78a8a385
commit
a40a54d4d8
|
|
@ -6,6 +6,8 @@ import (
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"pault.ag/go/topsort"
|
"pault.ag/go/topsort"
|
||||||
|
|
||||||
|
"github.com/docker-library/go-dockerlibrary/manifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cmdOffspring(c *cli.Context) error {
|
func cmdOffspring(c *cli.Context) error {
|
||||||
|
|
@ -27,6 +29,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
|
||||||
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
|
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uniq := c.Bool("uniq")
|
||||||
applyConstraints := c.Bool("apply-constraints")
|
applyConstraints := c.Bool("apply-constraints")
|
||||||
depth := c.Int("depth")
|
depth := c.Int("depth")
|
||||||
|
|
||||||
|
|
@ -87,7 +90,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// now the real work
|
// now the real work
|
||||||
seen := map[*topsort.Node]bool{}
|
seen := map[string]bool{}
|
||||||
for _, repo := range depsRepos {
|
for _, repo := range depsRepos {
|
||||||
r, err := fetch(repo)
|
r, err := fetch(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -101,8 +104,8 @@ func cmdFamily(parents bool, c *cli.Context) error {
|
||||||
|
|
||||||
// we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them
|
// we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them
|
||||||
tagRepo := path.Join(namespace, r.RepoName)
|
tagRepo := path.Join(namespace, r.RepoName)
|
||||||
for i, rawTag := range entry.Tags {
|
for _, rawTag := range entry.Tags {
|
||||||
tag := tagRepo+":"+rawTag
|
tag := tagRepo + ":" + rawTag
|
||||||
|
|
||||||
nodes := []topsortDepthNodes{}
|
nodes := []topsortDepthNodes{}
|
||||||
if parents {
|
if parents {
|
||||||
|
|
@ -123,11 +126,15 @@ func cmdFamily(parents bool, c *cli.Context) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, node := range depthNodes.nodes {
|
for _, node := range depthNodes.nodes {
|
||||||
if seen[node] {
|
seenKey := node.Name
|
||||||
|
if uniq {
|
||||||
|
seenKey = tagRepo + ":" + node.Value.(*manifest.Manifest2822Entry).Tags[0]
|
||||||
|
}
|
||||||
|
if seen[seenKey] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[node] = true
|
seen[seenKey] = true
|
||||||
fmt.Printf("%s\n", node.Name)
|
fmt.Printf("%s\n", seenKey)
|
||||||
if parents {
|
if parents {
|
||||||
nodes = append(nodes, topsortDepthNodes{
|
nodes = append(nodes, topsortDepthNodes{
|
||||||
depth: depthNodes.depth + 1,
|
depth: depthNodes.depth + 1,
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,7 @@ func main() {
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
commonFlags["apply-constraints"],
|
commonFlags["apply-constraints"],
|
||||||
commonFlags["depth"],
|
commonFlags["depth"],
|
||||||
|
commonFlags["uniq"],
|
||||||
},
|
},
|
||||||
Before: subcommandBeforeFactory("children"),
|
Before: subcommandBeforeFactory("children"),
|
||||||
Action: cmdOffspring,
|
Action: cmdOffspring,
|
||||||
|
|
@ -326,6 +327,7 @@ func main() {
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
commonFlags["apply-constraints"],
|
commonFlags["apply-constraints"],
|
||||||
commonFlags["depth"],
|
commonFlags["depth"],
|
||||||
|
commonFlags["uniq"],
|
||||||
},
|
},
|
||||||
Before: subcommandBeforeFactory("parents"),
|
Before: subcommandBeforeFactory("parents"),
|
||||||
Action: cmdParents,
|
Action: cmdParents,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue