diff --git a/commands/build.go b/commands/build.go index 7982ce32..9ae01139 100644 --- a/commands/build.go +++ b/commands/build.go @@ -629,6 +629,8 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D } flags.StringVar(&options.printFunc, "call", "build", `Set method for evaluating build ("check", "outline", "targets")`) + flags.VarPF(callAlias(options, "check"), "check", "", `Shorthand for "--call=check"`) + flags.Lookup("check").NoOptDefVal = "true" // hidden flags var ignore string @@ -1003,6 +1005,20 @@ func maybeJSONArray(v string) []string { return []string{v} } +func callAlias(options *buildOptions, value string) cobrautil.BoolFuncValue { + return func(s string) error { + v, err := strconv.ParseBool(s) + if err != nil { + return err + } + + if v { + options.printFunc = value + } + return nil + } +} + // timeBuildCommand will start a timer for timing the build command. It records the time when the returned // function is invoked into a metric. func timeBuildCommand(mp metric.MeterProvider, attrs attribute.Set) func(err error) { diff --git a/docs/reference/buildx_build.md b/docs/reference/buildx_build.md index 6170fc3a..13513f27 100644 --- a/docs/reference/buildx_build.md +++ b/docs/reference/buildx_build.md @@ -26,6 +26,7 @@ Start a build | [`--cache-to`](#cache-to) | `stringArray` | | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) | | `--call` | `string` | `build` | Set method for evaluating build (`check`, `outline`, `targets`) | | [`--cgroup-parent`](https://docs.docker.com/reference/cli/docker/image/build/#cgroup-parent) | `string` | | Set the parent cgroup for the `RUN` instructions during build | +| `--check` | | | Shorthand for `--call=check` | | `--detach` | | | Detach buildx server (supported only on linux) (EXPERIMENTAL) | | [`-f`](https://docs.docker.com/reference/cli/docker/image/build/#file), [`--file`](https://docs.docker.com/reference/cli/docker/image/build/#file) | `string` | | Name of the Dockerfile (default: `PATH/Dockerfile`) | | `--iidfile` | `string` | | Write the image ID to a file | diff --git a/docs/reference/buildx_debug_build.md b/docs/reference/buildx_debug_build.md index af9e7606..ca8b825f 100644 --- a/docs/reference/buildx_debug_build.md +++ b/docs/reference/buildx_debug_build.md @@ -22,6 +22,7 @@ Start a build | `--cache-to` | `stringArray` | | Cache export destinations (e.g., `user/app:cache`, `type=local,dest=path/to/dir`) | | `--call` | `string` | `build` | Set method for evaluating build (`check`, `outline`, `targets`) | | [`--cgroup-parent`](https://docs.docker.com/reference/cli/docker/image/build/#cgroup-parent) | `string` | | Set the parent cgroup for the `RUN` instructions during build | +| `--check` | | | Shorthand for `--call=check` | | `--detach` | | | Detach buildx server (supported only on linux) (EXPERIMENTAL) | | [`-f`](https://docs.docker.com/reference/cli/docker/image/build/#file), [`--file`](https://docs.docker.com/reference/cli/docker/image/build/#file) | `string` | | Name of the Dockerfile (default: `PATH/Dockerfile`) | | `--iidfile` | `string` | | Write the image ID to a file | diff --git a/util/cobrautil/boolfunc.go b/util/cobrautil/boolfunc.go new file mode 100644 index 00000000..53e9d368 --- /dev/null +++ b/util/cobrautil/boolfunc.go @@ -0,0 +1,11 @@ +package cobrautil + +type BoolFuncValue func(string) error + +func (f BoolFuncValue) Set(s string) error { return f(s) } + +func (f BoolFuncValue) String() string { return "" } + +func (f BoolFuncValue) Type() string { return "bool" } + +func (f BoolFuncValue) IsBoolFlag() bool { return true }