Skip to content

Commit b50ff38

Browse files
committed
Add "--build-order" to cat (and a couple minor bugfixes)
- fix parsing of empty `BASHBREW_ARCH_NAMESPACES` - better (more contextual) error messages from `bashbrew remote arches`
1 parent 7703558 commit b50ff38

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cmd/bashbrew/cmd-cat.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ func cmdCat(c *cli.Context) error {
3636
format := c.String("format")
3737
formatFile := c.String("format-file")
3838

39+
buildOrder := c.Bool("build-order")
40+
if buildOrder {
41+
repos, err = sortRepos(repos, false) // do not (cannot) applyConstraints (we'd have to modify the actual objects to remove Entries)
42+
if err != nil {
43+
return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err)
44+
}
45+
}
46+
3947
templateName := "--format"
4048
tmplMultiErr := fmt.Errorf(`failed parsing --format %q`, format)
4149
if formatFile != "" {

cmd/bashbrew/cmd-remote-arches.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ func cmdRemoteArches(c *cli.Context) error {
2222
for _, arg := range args {
2323
img, err := registry.Resolve(ctx, arg)
2424
if err != nil {
25-
return err
25+
return fmt.Errorf("failed to resolve %s: %w", arg, err)
2626
}
2727

2828
arches, err := img.Architectures(ctx)
2929
if err != nil {
30-
return err
30+
return fmt.Errorf("failed to query arches of %s: %w", arg, err)
3131
}
3232

3333
if doJson {

cmd/bashbrew/main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ func main() {
188188

189189
archNamespaces = map[string]string{}
190190
for _, archMapping := range c.GlobalStringSlice("arch-namespace") {
191+
if archMapping == "" {
192+
// "BASHBREW_ARCH_NAMESPACES=" (should be the same as the empty list)
193+
continue
194+
}
191195
splitArchMapping := strings.SplitN(archMapping, "=", 2)
192196
splitArch, splitNamespace := strings.TrimSpace(splitArchMapping[0]), strings.TrimSpace(splitArchMapping[1])
193197
archNamespaces[splitArch] = splitNamespace
@@ -224,6 +228,10 @@ func main() {
224228
Name: "arch-filter",
225229
Usage: "like apply-constraints, but only for Architectures",
226230
},
231+
"build-order": cli.BoolFlag{
232+
Name: "build-order",
233+
Usage: "sort by the order repos would need to build (topsort)",
234+
},
227235
"depth": cli.IntFlag{
228236
Name: "depth",
229237
Value: 0,
@@ -258,10 +266,7 @@ func main() {
258266
commonFlags["uniq"],
259267
commonFlags["apply-constraints"],
260268
commonFlags["arch-filter"],
261-
cli.BoolFlag{
262-
Name: "build-order",
263-
Usage: "sort by the order repos would need to build (topsort)",
264-
},
269+
commonFlags["build-order"],
265270
cli.BoolFlag{
266271
Name: "repos",
267272
Usage: `list only repos, not repo:tag (unless "repo:tag" is explicitly specified)`,
@@ -380,6 +385,7 @@ func main() {
380385
Name: "format-file, F",
381386
Usage: "use the contents of `FILE` for \"--format\"",
382387
},
388+
commonFlags["build-order"],
383389
},
384390
Before: subcommandBeforeFactory("cat"),
385391
Action: cmdCat,

0 commit comments

Comments
 (0)