Skip to content

Commit

Permalink
Merge pull request #63 from infosiftr/fetch
Browse files Browse the repository at this point in the history
Add "bashbrew fetch" command
  • Loading branch information
tianon authored Jan 31, 2023
2 parents 5990ace + cec429f commit 82fa443
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/bashbrew/cmd-cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func cmdCat(c *cli.Context) error {
"arch": func() string {
return arch
},
"gitCache": func() (string, error) {
err := ensureGitInit()
if err != nil {
return "", err
}
return gitCache(), nil
},
"ociPlatform": func(arch string) *architecture.OCIPlatform {
if ociArch, ok := architecture.SupportedArches[arch]; ok {
return &ociArch
Expand Down
51 changes: 51 additions & 0 deletions cmd/bashbrew/cmd-fetch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"fmt"
"os"

"github.com/urfave/cli"
)

func cmdFetch(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)
}

applyConstraints := c.Bool("apply-constraints")
archFilter := c.Bool("arch-filter")

for _, repo := range repos {
r, err := fetch(repo)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
}

for _, entry := range r.Entries() {
if applyConstraints && r.SkipConstraints(entry) {
continue
}
if archFilter && !entry.HasArchitecture(arch) {
continue
}

arches := entry.Architectures
if applyConstraints || archFilter {
arches = []string{arch}
}

for _, entryArch := range arches {
commit, err := r.fetchGitRepo(entryArch, entry)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching git repo for %q (tags %q on arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
}
if debugFlag {
fmt.Fprintf(os.Stderr, "DEBUG: fetched %s (%q, %q)\n", commit, r.EntryIdentifier(entry), entryArch)
}
}
}
}

return nil
}
13 changes: 13 additions & 0 deletions cmd/bashbrew/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,19 @@ func main() {

Category: "plumbing",
},
{
Name: "fetch",
Usage: "ensure Git contents are local",
Flags: []cli.Flag{
commonFlags["all"],
commonFlags["apply-constraints"],
commonFlags["arch-filter"],
},
Before: subcommandBeforeFactory("fetch"),
Action: cmdFetch,

Category: "plumbing",
},
{
Name: "remote",
Usage: "query registries for bashbrew-related data",
Expand Down

0 comments on commit 82fa443

Please sign in to comment.