Skip to content

Commit c922da0

Browse files
committed
Add "--target-namespace" to both "push" and "put-shared" and make "tag" more intuitive
1 parent 4029557 commit c922da0

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

go/src/bashbrew/cmd-push.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ func cmdPush(c *cli.Context) error {
1616
}
1717

1818
uniq := c.Bool("uniq")
19+
targetNamespace := c.String("target-namespace")
1920
dryRun := c.Bool("dry-run")
2021
force := c.Bool("force")
2122

22-
if namespace == "" {
23-
return fmt.Errorf(`"--namespace" is a required flag for "push"`)
23+
if targetNamespace == "" {
24+
targetNamespace = namespace
25+
}
26+
if targetNamespace == "" {
27+
return fmt.Errorf(`either "--target-namespace" or "--namespace" is a required flag for "push"`)
2428
}
2529

2630
for _, repo := range repos {
@@ -29,7 +33,7 @@ func cmdPush(c *cli.Context) error {
2933
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
3034
}
3135

32-
tagRepo := path.Join(namespace, r.RepoName)
36+
tagRepo := path.Join(targetNamespace, r.RepoName)
3337
for _, entry := range r.Entries() {
3438
if r.SkipConstraints(entry) {
3539
continue

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ func cmdPutShared(c *cli.Context) error {
8484
}
8585

8686
dryRun := c.Bool("dry-run")
87+
targetNamespace := c.String("target-namespace")
8788
force := c.Bool("force")
8889
singleArch := c.Bool("single-arch")
8990

90-
if namespace == "" {
91-
return fmt.Errorf(`"--namespace" is a required flag for "put-shared"`)
91+
if targetNamespace == "" {
92+
targetNamespace = namespace
93+
}
94+
if targetNamespace == "" {
95+
return fmt.Errorf(`either "--target-namespace" or "--namespace" is a required flag for "put-shared"`)
9296
}
9397

9498
for _, repo := range repos {
@@ -97,7 +101,7 @@ func cmdPutShared(c *cli.Context) error {
97101
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
98102
}
99103

100-
targetRepo := path.Join(namespace, r.RepoName)
104+
targetRepo := path.Join(targetNamespace, r.RepoName)
101105

102106
sharedTagGroups := []manifest.SharedTagGroup{}
103107

go/src/bashbrew/cmd-tag.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ func cmdTag(c *cli.Context) error {
1717
targetNamespace := c.String("target-namespace")
1818
dryRun := c.Bool("dry-run")
1919

20-
if namespace == "" {
21-
return fmt.Errorf(`"--namespace" is a required flag for "tag"`)
22-
}
2320
if targetNamespace == "" {
2421
return fmt.Errorf(`"--target-namespace" is a required flag for "tag"`)
2522
}

go/src/bashbrew/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func main() {
214214
Name: "force",
215215
Usage: "always push (skip the clever Hub API lookups that no-op things sooner if a push doesn't seem necessary)",
216216
},
217+
"target-namespace": cli.StringFlag{
218+
Name: "target-namespace",
219+
Usage: `target namespace to act into ("docker tag namespace/repo:tag target-namespace/repo:tag", "docker push target-namespace/repo:tag")`,
220+
},
217221
}
218222

219223
app.Commands = []cli.Command{
@@ -261,10 +265,7 @@ func main() {
261265
commonFlags["all"],
262266
commonFlags["uniq"],
263267
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-
},
268+
commonFlags["target-namespace"],
268269
},
269270
Before: subcommandBeforeFactory("tag"),
270271
Action: cmdTag,
@@ -277,6 +278,7 @@ func main() {
277278
commonFlags["uniq"],
278279
commonFlags["dry-run"],
279280
commonFlags["force"],
281+
commonFlags["target-namespace"],
280282
},
281283
Before: subcommandBeforeFactory("push"),
282284
Action: cmdPush,
@@ -288,6 +290,7 @@ func main() {
288290
commonFlags["all"],
289291
commonFlags["dry-run"],
290292
commonFlags["force"],
293+
commonFlags["target-namespace"],
291294
cli.BoolFlag{
292295
Name: "single-arch",
293296
Usage: `only act on the current architecture (for pushing "amd64/hello-world:latest", for example)`,

0 commit comments

Comments
 (0)