Skip to content

Commit

Permalink
build: change --no-console to --console=[true|false|auto]
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Vass <[email protected]>
  • Loading branch information
Tibor Vass committed Jun 13, 2018
1 parent 00792d1 commit b1f3b4b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type buildOptions struct {
isolation string
quiet bool
noCache bool
noConsole bool
console opts.NullableBool
rm bool
forceRm bool
pull bool
Expand Down Expand Up @@ -152,9 +152,9 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
flags.SetAnnotation("stream", "experimental", nil)
flags.SetAnnotation("stream", "version", []string{"1.31"})

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

Expand Down
4 changes: 3 additions & 1 deletion cli/command/image/build_buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ func doBuild(ctx context.Context, eg *errgroup.Group, dockerCli command.Cli, opt
displayStatus := func(displayCh chan *client.SolveStatus) {
var c console.Console
out := os.Stderr
if cons, err := console.ConsoleFromFile(out); err == nil && !options.noConsole {
// TODO: Handle interactive output in non-interactive environment.
consoleOpt := options.console.Value()
if cons, err := console.ConsoleFromFile(out); err == nil && (consoleOpt == nil || *consoleOpt) {
c = cons
}
// not using shared context to not disrupt display but let is finish reporting errors
Expand Down
32 changes: 32 additions & 0 deletions opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"path"
"regexp"
"strconv"
"strings"

"github.com/docker/docker/api/types/filters"
Expand Down Expand Up @@ -486,3 +487,34 @@ func (m *MemSwapBytes) UnmarshalJSON(s []byte) error {
b := MemBytes(*m)
return b.UnmarshalJSON(s)
}

// NullableBool is a type for tri-state boolean options
type NullableBool struct {
b *bool
}

func (n *NullableBool) Type() string {
return ""
}

func (n *NullableBool) Value() *bool {
return n.b
}

func (n *NullableBool) Set(value string) error {
if value != "auto" && value != "" {
if b, err := strconv.ParseBool(value); err != nil {
return err
} else {
n.b = &b
}
}
return nil
}

func (n *NullableBool) String() string {
if n.b == nil {
return "auto"
}
return strconv.FormatBool(*n.b)
}

0 comments on commit b1f3b4b

Please sign in to comment.