Skip to content

Commit 82fa443

Browse files
authored
Merge pull request #63 from infosiftr/fetch
Add "bashbrew fetch" command
2 parents 5990ace + cec429f commit 82fa443

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

cmd/bashbrew/cmd-cat.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ func cmdCat(c *cli.Context) error {
5656
"arch": func() string {
5757
return arch
5858
},
59+
"gitCache": func() (string, error) {
60+
err := ensureGitInit()
61+
if err != nil {
62+
return "", err
63+
}
64+
return gitCache(), nil
65+
},
5966
"ociPlatform": func(arch string) *architecture.OCIPlatform {
6067
if ociArch, ok := architecture.SupportedArches[arch]; ok {
6168
return &ociArch

cmd/bashbrew/cmd-fetch.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/urfave/cli"
8+
)
9+
10+
func cmdFetch(c *cli.Context) error {
11+
repos, err := repos(c.Bool("all"), c.Args()...)
12+
if err != nil {
13+
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
14+
}
15+
16+
applyConstraints := c.Bool("apply-constraints")
17+
archFilter := c.Bool("arch-filter")
18+
19+
for _, repo := range repos {
20+
r, err := fetch(repo)
21+
if err != nil {
22+
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
23+
}
24+
25+
for _, entry := range r.Entries() {
26+
if applyConstraints && r.SkipConstraints(entry) {
27+
continue
28+
}
29+
if archFilter && !entry.HasArchitecture(arch) {
30+
continue
31+
}
32+
33+
arches := entry.Architectures
34+
if applyConstraints || archFilter {
35+
arches = []string{arch}
36+
}
37+
38+
for _, entryArch := range arches {
39+
commit, err := r.fetchGitRepo(entryArch, entry)
40+
if err != nil {
41+
return cli.NewMultiError(fmt.Errorf(`failed fetching git repo for %q (tags %q on arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
42+
}
43+
if debugFlag {
44+
fmt.Fprintf(os.Stderr, "DEBUG: fetched %s (%q, %q)\n", commit, r.EntryIdentifier(entry), entryArch)
45+
}
46+
}
47+
}
48+
}
49+
50+
return nil
51+
}

cmd/bashbrew/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,19 @@ func main() {
402402

403403
Category: "plumbing",
404404
},
405+
{
406+
Name: "fetch",
407+
Usage: "ensure Git contents are local",
408+
Flags: []cli.Flag{
409+
commonFlags["all"],
410+
commonFlags["apply-constraints"],
411+
commonFlags["arch-filter"],
412+
},
413+
Before: subcommandBeforeFactory("fetch"),
414+
Action: cmdFetch,
415+
416+
Category: "plumbing",
417+
},
405418
{
406419
Name: "remote",
407420
Usage: "query registries for bashbrew-related data",

0 commit comments

Comments
 (0)