Skip to content

Commit 5b2ecca

Browse files
committed
simplify signal handling for cobra context
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 650a7af commit 5b2ecca

15 files changed

Lines changed: 35 additions & 77 deletions

File tree

commands/bake.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/docker/buildx/builder"
1616
"github.com/docker/buildx/localstate"
1717
"github.com/docker/buildx/util/buildflags"
18-
"github.com/docker/buildx/util/cobrautil"
1918
"github.com/docker/buildx/util/cobrautil/completion"
2019
"github.com/docker/buildx/util/confutil"
2120
"github.com/docker/buildx/util/desktop"
@@ -262,7 +261,7 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
262261
Use: "bake [OPTIONS] [TARGET...]",
263262
Aliases: []string{"f"},
264263
Short: "Build from a file",
265-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
264+
RunE: func(cmd *cobra.Command, args []string) error {
266265
// reset to nil to avoid override is unset
267266
if !cmd.Flags().Lookup("no-cache").Changed {
268267
cFlags.noCache = nil
@@ -274,7 +273,7 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
274273
options.metadataFile = cFlags.metadataFile
275274
// Other common flags (noCache, pull and progress) are processed in runBake function.
276275
return runBake(cmd.Context(), dockerCli, args, options, cFlags)
277-
}),
276+
},
278277
ValidArgsFunction: completion.BakeTargets(options.files),
279278
}
280279

commands/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D
461461
Aliases: []string{"b"},
462462
Short: "Start a build",
463463
Args: cli.ExactArgs(1),
464-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
464+
RunE: func(cmd *cobra.Command, args []string) error {
465465
options.contextPath = args[0]
466466
options.builder = rootOpts.builder
467467
options.metadataFile = cFlags.metadataFile
@@ -485,7 +485,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D
485485
}
486486

487487
return runBuild(cmd.Context(), dockerCli, *options)
488-
}),
488+
},
489489
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
490490
return nil, cobra.ShellCompDirectiveFilterDirs
491491
},

commands/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func createCmd(dockerCli command.Cli) *cobra.Command {
9595
Use: "create [OPTIONS] [CONTEXT|ENDPOINT]",
9696
Short: "Create a new builder instance",
9797
Args: cli.RequiresMaxArgs(1),
98-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
98+
RunE: func(cmd *cobra.Command, args []string) error {
9999
return runCreate(cmd.Context(), dockerCli, options, args)
100-
}),
100+
},
101101
ValidArgsFunction: completion.Disable,
102102
}
103103

commands/diskusage.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/docker/buildx/builder"
13-
"github.com/docker/buildx/util/cobrautil"
1413
"github.com/docker/buildx/util/cobrautil/completion"
1514
"github.com/docker/cli/cli"
1615
"github.com/docker/cli/cli/command"
@@ -111,10 +110,10 @@ func duCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
111110
Use: "du",
112111
Short: "Disk usage",
113112
Args: cli.NoArgs,
114-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
113+
RunE: func(cmd *cobra.Command, args []string) error {
115114
options.builder = rootOpts.builder
116115
return runDiskUsage(cmd.Context(), dockerCli, options)
117-
}),
116+
},
118117
ValidArgsFunction: completion.Disable,
119118
}
120119

commands/imagetools/create.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/distribution/reference"
1111
"github.com/docker/buildx/builder"
12-
"github.com/docker/buildx/util/cobrautil"
1312
"github.com/docker/buildx/util/cobrautil/completion"
1413
"github.com/docker/buildx/util/imagetools"
1514
"github.com/docker/buildx/util/progress"
@@ -270,10 +269,10 @@ func createCmd(dockerCli command.Cli, opts RootOptions) *cobra.Command {
270269
cmd := &cobra.Command{
271270
Use: "create [OPTIONS] [SOURCE] [SOURCE...]",
272271
Short: "Create a new image based on source images",
273-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
272+
RunE: func(cmd *cobra.Command, args []string) error {
274273
options.builder = *opts.Builder
275274
return runCreate(cmd.Context(), dockerCli, options, args)
276-
}),
275+
},
277276
ValidArgsFunction: completion.Disable,
278277
}
279278

commands/imagetools/inspect.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55

66
"github.com/docker/buildx/builder"
7-
"github.com/docker/buildx/util/cobrautil"
87
"github.com/docker/buildx/util/cobrautil/completion"
98
"github.com/docker/buildx/util/imagetools"
109
"github.com/docker/cli-docs-tool/annotation"
@@ -49,10 +48,10 @@ func inspectCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command {
4948
Use: "inspect [OPTIONS] NAME",
5049
Short: "Show details of an image in the registry",
5150
Args: cli.ExactArgs(1),
52-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
51+
RunE: func(cmd *cobra.Command, args []string) error {
5352
options.builder = *rootOpts.Builder
5453
return runInspect(cmd.Context(), dockerCli, options, args[0])
55-
}),
54+
},
5655
ValidArgsFunction: completion.Disable,
5756
}
5857

commands/inspect.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/docker/buildx/builder"
1313
"github.com/docker/buildx/driver"
14-
"github.com/docker/buildx/util/cobrautil"
1514
"github.com/docker/buildx/util/cobrautil/completion"
1615
"github.com/docker/buildx/util/platformutil"
1716
"github.com/docker/cli/cli"
@@ -143,13 +142,13 @@ func inspectCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
143142
Use: "inspect [NAME]",
144143
Short: "Inspect current builder instance",
145144
Args: cli.RequiresMaxArgs(1),
146-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
145+
RunE: func(cmd *cobra.Command, args []string) error {
147146
options.builder = rootOpts.builder
148147
if len(args) > 0 {
149148
options.builder = args[0]
150149
}
151150
return runInspect(cmd.Context(), dockerCli, options)
152-
}),
151+
},
153152
ValidArgsFunction: completion.BuilderNames(dockerCli),
154153
}
155154

commands/ls.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ func lsCmd(dockerCli command.Cli) *cobra.Command {
9999
Use: "ls",
100100
Short: "List builder instances",
101101
Args: cli.ExactArgs(0),
102-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
102+
RunE: func(cmd *cobra.Command, args []string) error {
103103
return runLs(cmd.Context(), dockerCli, options)
104-
}),
104+
},
105105
ValidArgsFunction: completion.Disable,
106106
}
107107

commands/prune.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"time"
1010

1111
"github.com/docker/buildx/builder"
12-
"github.com/docker/buildx/util/cobrautil"
1312
"github.com/docker/buildx/util/cobrautil/completion"
1413
"github.com/docker/cli/cli"
1514
"github.com/docker/cli/cli/command"
@@ -135,10 +134,10 @@ func pruneCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
135134
Use: "prune",
136135
Short: "Remove build cache",
137136
Args: cli.NoArgs,
138-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
137+
RunE: func(cmd *cobra.Command, args []string) error {
139138
options.builder = rootOpts.builder
140139
return runPrune(cmd.Context(), dockerCli, options)
141-
}),
140+
},
142141
ValidArgsFunction: completion.Disable,
143142
}
144143

commands/rm.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/docker/buildx/builder"
99
"github.com/docker/buildx/store"
1010
"github.com/docker/buildx/store/storeutil"
11-
"github.com/docker/buildx/util/cobrautil"
1211
"github.com/docker/buildx/util/cobrautil/completion"
1312
"github.com/docker/cli/cli/command"
1413
"github.com/pkg/errors"
@@ -98,7 +97,7 @@ func rmCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
9897
cmd := &cobra.Command{
9998
Use: "rm [OPTIONS] [NAME] [NAME...]",
10099
Short: "Remove one or more builder instances",
101-
RunE: cobrautil.ConfigureContext(func(cmd *cobra.Command, args []string) error {
100+
RunE: func(cmd *cobra.Command, args []string) error {
102101
options.builders = []string{rootOpts.builder}
103102
if len(args) > 0 {
104103
if options.allInactive {
@@ -107,7 +106,7 @@ func rmCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
107106
options.builders = args
108107
}
109108
return runRm(cmd.Context(), dockerCli, options)
110-
}),
109+
},
111110
ValidArgsFunction: completion.BuilderNames(dockerCli),
112111
}
113112

0 commit comments

Comments
 (0)