Skip to content

Commit 4029557

Browse files
committed
Make "--namespace" a global parameter that affects every command (and add "--target-namespace" to "bashbrew tag")
1 parent bc4037d commit 4029557

File tree

11 files changed

+50
-55
lines changed

11 files changed

+50
-55
lines changed

go/src/bashbrew/cmd-build.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ func cmdBuild(c *cli.Context) error {
1212
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
1313
}
1414

15-
namespace := c.String("namespace")
16-
repos, err = sortRepos(repos, true, namespace)
15+
repos, err = sortRepos(repos, true)
1716
if err != nil {
1817
return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err)
1918
}
@@ -34,7 +33,7 @@ func cmdBuild(c *cli.Context) error {
3433
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
3534
}
3635

37-
entries, err := r.SortedEntries(true, namespace)
36+
entries, err := r.SortedEntries(true)
3837
if err != nil {
3938
return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err)
4039
}

go/src/bashbrew/cmd-cat.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func cmdCat(c *cli.Context) error {
5555
"arch": func() string {
5656
return arch
5757
},
58+
"namespace": func() string {
59+
return namespace
60+
},
5861
"archNamespace": func(arch string) string {
5962
return archNamespaces[arch]
6063
},

go/src/bashbrew/cmd-deps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
5050
continue
5151
}
5252

53-
for _, tag := range r.Tags("", false, entry) {
53+
for _, tag := range r.Tags(namespace, false, entry) {
5454
network.AddNode(tag, entry)
5555
}
5656
}
@@ -78,7 +78,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
7878
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
7979
}
8080
for _, from := range froms {
81-
for _, tag := range r.Tags("", false, entry) {
81+
for _, tag := range r.Tags(namespace, false, entry) {
8282
network.AddEdge(from, tag)
8383
}
8484
}
@@ -99,7 +99,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
9999
continue
100100
}
101101

102-
for _, tag := range r.Tags("", uniq, entry) {
102+
for _, tag := range r.Tags(namespace, uniq, entry) {
103103
nodes := []topsortDepthNodes{}
104104
if parents {
105105
nodes = append(nodes, topsortDepthNodes{

go/src/bashbrew/cmd-from.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func cmdFrom(c *cli.Context) error {
1414
}
1515

1616
uniq := c.Bool("uniq")
17-
namespace := ""
1817
applyConstraints := c.Bool("apply-constraints")
1918

2019
for _, repo := range repos {

go/src/bashbrew/cmd-list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ func cmdList(c *cli.Context) error {
1414
}
1515

1616
uniq := c.Bool("uniq")
17-
namespace := c.String("namespace")
1817
applyConstraints := c.Bool("apply-constraints")
1918
onlyRepos := c.Bool("repos")
2019

2120
buildOrder := c.Bool("build-order")
2221
if buildOrder {
23-
repos, err = sortRepos(repos, applyConstraints, namespace)
22+
repos, err = sortRepos(repos, applyConstraints)
2423
if err != nil {
2524
return cli.NewMultiError(fmt.Errorf(`failed sorting repo list`), err)
2625
}
@@ -45,7 +44,7 @@ func cmdList(c *cli.Context) error {
4544

4645
var entries []*manifest.Manifest2822Entry
4746
if buildOrder {
48-
entries, err = r.SortedEntries(applyConstraints, namespace)
47+
entries, err = r.SortedEntries(applyConstraints)
4948
if err != nil {
5049
return cli.NewMultiError(fmt.Errorf(`failed sorting entries list for %q`, repo), err)
5150
}

go/src/bashbrew/cmd-push.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func cmdPush(c *cli.Context) error {
1616
}
1717

1818
uniq := c.Bool("uniq")
19-
namespace := c.String("namespace")
2019
dryRun := c.Bool("dry-run")
2120
force := c.Bool("force")
2221

go/src/bashbrew/cmd-put-shared.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ func cmdPutShared(c *cli.Context) error {
8383
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
8484
}
8585

86-
namespace := c.String("namespace")
8786
dryRun := c.Bool("dry-run")
8887
force := c.Bool("force")
8988
singleArch := c.Bool("single-arch")

go/src/bashbrew/cmd-tag.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ func cmdTag(c *cli.Context) error {
1414
}
1515

1616
uniq := c.Bool("uniq")
17-
namespace := c.String("namespace")
17+
targetNamespace := c.String("target-namespace")
1818
dryRun := c.Bool("dry-run")
1919

2020
if namespace == "" {
2121
return fmt.Errorf(`"--namespace" is a required flag for "tag"`)
2222
}
23+
if targetNamespace == "" {
24+
return fmt.Errorf(`"--target-namespace" is a required flag for "tag"`)
25+
}
2326

2427
for _, repo := range repos {
2528
r, err := fetch(repo)
@@ -33,12 +36,13 @@ func cmdTag(c *cli.Context) error {
3336
}
3437

3538
for _, tag := range r.Tags("", uniq, entry) {
36-
namespacedTag := path.Join(namespace, tag)
37-
fmt.Printf("Tagging %s\n", namespacedTag)
39+
sourceTag := path.Join(namespace, tag)
40+
targetTag := path.Join(targetNamespace, tag)
41+
fmt.Printf("Tagging %s\n", targetTag)
3842
if !dryRun {
39-
err = dockerTag(tag, namespacedTag)
43+
err = dockerTag(sourceTag, targetTag)
4044
if err != nil {
41-
return cli.NewMultiError(fmt.Errorf(`failed tagging %q as %q`, tag, namespacedTag), err)
45+
return cli.NewMultiError(fmt.Errorf(`failed tagging %q as %q`, sourceTag, targetTag), err)
4246
}
4347
}
4448
}

go/src/bashbrew/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ type FlagsConfigEntry struct {
2222
Cache string
2323
Debug string
2424
Unique string
25-
Namespace string
2625
BuildOrder string
2726
Pull string
2827

2928
Arch string
29+
Namespace string
3030
Constraints []string `delim:"," strip:"\n\r\t "`
3131
ExclusiveConstraints string
3232
ApplyConstraints string
@@ -50,9 +50,6 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) {
5050
if src.Unique != "" {
5151
dst.Unique = src.Unique
5252
}
53-
if src.Namespace != "" {
54-
dst.Namespace = src.Namespace
55-
}
5653
if src.BuildOrder != "" {
5754
dst.BuildOrder = src.BuildOrder
5855
}
@@ -62,6 +59,9 @@ func (dst *FlagsConfigEntry) Apply(src FlagsConfigEntry) {
6259
if src.Arch != "" {
6360
dst.Arch = src.Arch
6461
}
62+
if src.Namespace != "" {
63+
dst.Namespace = src.Namespace
64+
}
6565
if len(src.Constraints) > 0 {
6666
dst.Constraints = src.Constraints[:]
6767
}
@@ -84,6 +84,7 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} {
8484
"debug": config.Debug,
8585

8686
"arch": config.Arch,
87+
"namespace": config.Namespace,
8788
"constraint": config.Constraints,
8889
"exclusive-constraints": config.ExclusiveConstraints,
8990

@@ -92,7 +93,6 @@ func (config FlagsConfigEntry) Vars() map[string]map[string]interface{} {
9293

9394
"local": {
9495
"uniq": config.Unique,
95-
"namespace": config.Namespace,
9696
"build-order": config.BuildOrder,
9797
"pull": config.Pull,
9898

go/src/bashbrew/main.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
defaultCache string
2323

2424
arch string
25+
namespace string
2526
constraints []string
2627
exclusiveConstraints bool
2728

@@ -32,12 +33,13 @@ var (
3233

3334
// separated so that FlagsConfig.ApplyTo can access them
3435
flagEnvVars = map[string]string{
35-
"debug": "BASHBREW_DEBUG",
36-
"arch": "BASHBREW_ARCH",
37-
"config": "BASHBREW_CONFIG",
38-
"library": "BASHBREW_LIBRARY",
39-
"cache": "BASHBREW_CACHE",
40-
"pull": "BASHBREW_PULL",
36+
"debug": "BASHBREW_DEBUG",
37+
"arch": "BASHBREW_ARCH",
38+
"namespace": "BASHBREW_NAMESPACE",
39+
"config": "BASHBREW_CONFIG",
40+
"library": "BASHBREW_LIBRARY",
41+
"cache": "BASHBREW_CACHE",
42+
"pull": "BASHBREW_PULL",
4143

4244
"constraint": "BASHBREW_CONSTRAINTS",
4345
"arch-namespace": "BASHBREW_ARCH_NAMESPACES",
@@ -93,6 +95,11 @@ func main() {
9395
EnvVar: flagEnvVars["arch"],
9496
Usage: "the current platform architecture",
9597
},
98+
cli.StringFlag{
99+
Name: "namespace",
100+
EnvVar: flagEnvVars["namespace"],
101+
Usage: "a repo namespace to act upon/in",
102+
},
96103
cli.StringSliceFlag{
97104
Name: "constraint",
98105
EnvVar: flagEnvVars["constraint"],
@@ -156,6 +163,7 @@ func main() {
156163
noSortFlag = c.GlobalBool("no-sort")
157164

158165
arch = c.GlobalString("arch")
166+
namespace = c.GlobalString("namespace")
159167
constraints = c.GlobalStringSlice("constraint")
160168
exclusiveConstraints = c.GlobalBool("exclusive-constraints")
161169

@@ -189,10 +197,6 @@ func main() {
189197
Name: "uniq, unique",
190198
Usage: "only act upon the first tag of each entry",
191199
},
192-
"namespace": cli.StringFlag{
193-
Name: "namespace",
194-
Usage: "a repo namespace to act upon/in",
195-
},
196200
"apply-constraints": cli.BoolFlag{
197201
Name: "apply-constraints",
198202
Usage: "apply Constraints as if repos were building",
@@ -220,7 +224,6 @@ func main() {
220224
Flags: []cli.Flag{
221225
commonFlags["all"],
222226
commonFlags["uniq"],
223-
commonFlags["namespace"],
224227
commonFlags["apply-constraints"],
225228
cli.BoolFlag{
226229
Name: "build-order",
@@ -240,7 +243,6 @@ func main() {
240243
Flags: []cli.Flag{
241244
commonFlags["all"],
242245
commonFlags["uniq"],
243-
commonFlags["namespace"],
244246
cli.StringFlag{
245247
Name: "pull",
246248
Value: "missing",
@@ -258,8 +260,11 @@ func main() {
258260
Flags: []cli.Flag{
259261
commonFlags["all"],
260262
commonFlags["uniq"],
261-
commonFlags["namespace"],
262263
commonFlags["dry-run"],
264+
cli.StringFlag{
265+
Name: "target-namespace",
266+
Usage: `target namespace to tag into ("docker tag namespace/repo:tag target-namespace/repo:tag")`,
267+
},
263268
},
264269
Before: subcommandBeforeFactory("tag"),
265270
Action: cmdTag,
@@ -270,7 +275,6 @@ func main() {
270275
Flags: []cli.Flag{
271276
commonFlags["all"],
272277
commonFlags["uniq"],
273-
commonFlags["namespace"],
274278
commonFlags["dry-run"],
275279
commonFlags["force"],
276280
},
@@ -282,7 +286,6 @@ func main() {
282286
Usage: `update shared tags in the registry (and multi-architecture tags)`,
283287
Flags: []cli.Flag{
284288
commonFlags["all"],
285-
commonFlags["namespace"],
286289
commonFlags["dry-run"],
287290
commonFlags["force"],
288291
cli.BoolFlag{

0 commit comments

Comments
 (0)