Skip to content

Commit 5a103e1

Browse files
author
Tibor Vass
committed
build: change --no-console to --console=[true|false|auto]
Signed-off-by: Tibor Vass <[email protected]>
1 parent 00792d1 commit 5a103e1

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

cli/command/image/build.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type buildOptions struct {
5757
isolation string
5858
quiet bool
5959
noCache bool
60-
noConsole bool
60+
console opts.NullableBool
6161
rm bool
6262
forceRm bool
6363
pull bool
@@ -152,9 +152,9 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
152152
flags.SetAnnotation("stream", "experimental", nil)
153153
flags.SetAnnotation("stream", "version", []string{"1.31"})
154154

155-
flags.BoolVar(&options.noConsole, "no-console", false, "Show non-console output (with buildkit only)")
156-
flags.SetAnnotation("no-console", "experimental", nil)
157-
flags.SetAnnotation("no-console", "version", []string{"1.38"})
155+
flags.Var(&options.console, "console", "Show console output (with buildkit only) (true, false, auto)")
156+
flags.SetAnnotation("console", "experimental", nil)
157+
flags.SetAnnotation("console", "version", []string{"1.38"})
158158
return cmd
159159
}
160160

cli/command/image/build_buildkit.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ func doBuild(ctx context.Context, eg *errgroup.Group, dockerCli command.Cli, opt
191191
displayStatus := func(displayCh chan *client.SolveStatus) {
192192
var c console.Console
193193
out := os.Stderr
194-
if cons, err := console.ConsoleFromFile(out); err == nil && !options.noConsole {
194+
// TODO: Handle interactive output in non-interactive environment.
195+
consoleOpt := options.console.Value()
196+
if cons, err := console.ConsoleFromFile(out); err == nil && (consoleOpt == nil || *consoleOpt) {
195197
c = cons
196198
}
197199
// not using shared context to not disrupt display but let is finish reporting errors

opts/opts.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"path"
88
"regexp"
9+
"strconv"
910
"strings"
1011

1112
"github.com/docker/docker/api/types/filters"
@@ -486,3 +487,38 @@ func (m *MemSwapBytes) UnmarshalJSON(s []byte) error {
486487
b := MemBytes(*m)
487488
return b.UnmarshalJSON(s)
488489
}
490+
491+
// NullableBool is a type for tri-state boolean options
492+
type NullableBool struct {
493+
b *bool
494+
}
495+
496+
// Type returns the type
497+
func (n *NullableBool) Type() string {
498+
return ""
499+
}
500+
501+
// Value returns the value in *bool
502+
func (n *NullableBool) Value() *bool {
503+
return n.b
504+
}
505+
506+
// Set sets the value. If value is empty string or "auto", nil is set.
507+
// Otherwise true or false are set based on flag.Bool behavior.
508+
func (n *NullableBool) Set(value string) error {
509+
if value != "auto" && value != "" {
510+
b, err := strconv.ParseBool(value)
511+
if err != nil {
512+
return err
513+
}
514+
n.b = &b
515+
}
516+
return nil
517+
}
518+
519+
func (n *NullableBool) String() string {
520+
if n.b == nil {
521+
return "auto"
522+
}
523+
return strconv.FormatBool(*n.b)
524+
}

0 commit comments

Comments
 (0)