forked from docker-library/bashbrew
/
cmd-list.go
72 lines (61 loc) · 1.54 KB
/
cmd-list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"path"
"github.com/khulnasoft/bashbrew/manifest"
"github.com/urfave/cli"
)
func cmdList(c *cli.Context) error {
repos, err := repos(c.Bool("all"), c.Args()...)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
}
uniq := c.Bool("uniq")
applyConstraints := c.Bool("apply-constraints")
archFilter := c.Bool("arch-filter")
onlyRepos := c.Bool("repos")
buildOrder := c.Bool("build-order")
if buildOrder {
repos, err = sortRepos(repos, applyConstraints)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err)
}
}
for _, repo := range repos {
r, err := fetch(repo)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
}
if onlyRepos {
if r.TagEntry == nil {
fmt.Printf("%s\n", path.Join(namespace, r.RepoName))
} else {
for _, tag := range r.Tags(namespace, uniq, r.TagEntry) {
fmt.Printf("%s\n", tag)
}
}
continue
}
var entries []*manifest.Manifest2822Entry
if buildOrder {
entries, err = r.SortedEntries(applyConstraints)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err)
}
} else {
entries = r.Entries()
}
for _, entry := range entries {
if applyConstraints && r.SkipConstraints(entry) {
continue
}
if archFilter && !entry.HasArchitecture(arch) {
continue
}
for _, tag := range r.Tags(namespace, uniq, entry) {
fmt.Printf("%s\n", tag)
}
}
}
return nil
}