| ... | ... |
@@ -375,7 +375,7 @@ type StdoutFormater struct {
|
| 375 | 375 |
} |
| 376 | 376 |
|
| 377 | 377 |
func (sf *StdoutFormater) Write(buf []byte) (int, error) {
|
| 378 |
- formattedBuf := sf.StreamFormatter.FormatStatus("", "%s", string(buf))
|
|
| 378 |
+ formattedBuf := sf.StreamFormatter.FormatStream(string(buf)) |
|
| 379 | 379 |
n, err := sf.Writer.Write(formattedBuf) |
| 380 | 380 |
if n != len(formattedBuf) {
|
| 381 | 381 |
return n, io.ErrShortWrite |
| ... | ... |
@@ -389,7 +389,7 @@ type StderrFormater struct {
|
| 389 | 389 |
} |
| 390 | 390 |
|
| 391 | 391 |
func (sf *StderrFormater) Write(buf []byte) (int, error) {
|
| 392 |
- formattedBuf := sf.StreamFormatter.FormatStatus("", "%s", "\033[91m"+string(buf)+"\033[0m")
|
|
| 392 |
+ formattedBuf := sf.StreamFormatter.FormatStream("\033[91m" + string(buf) + "\033[0m")
|
|
| 393 | 393 |
n, err := sf.Writer.Write(formattedBuf) |
| 394 | 394 |
if n != len(formattedBuf) {
|
| 395 | 395 |
return n, io.ErrShortWrite |
| ... | ... |
@@ -229,8 +229,6 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
| 229 | 229 |
if context != nil {
|
| 230 | 230 |
headers.Set("Content-Type", "application/tar")
|
| 231 | 231 |
} |
| 232 |
- // Temporary hack to fix displayJSON behavior |
|
| 233 |
- cli.isTerminal = false |
|
| 234 | 232 |
err = cli.stream("POST", fmt.Sprintf("/build?%s", v.Encode()), body, cli.out, headers)
|
| 235 | 233 |
if jerr, ok := err.(*utils.JSONError); ok {
|
| 236 | 234 |
return &utils.StatusError{Status: jerr.Message, StatusCode: jerr.Code}
|
| ... | ... |
@@ -66,6 +66,7 @@ func (p *JSONProgress) String() string {
|
| 66 | 66 |
} |
| 67 | 67 |
|
| 68 | 68 |
type JSONMessage struct {
|
| 69 |
+ Stream string `json:"stream,omitempty"` |
|
| 69 | 70 |
Status string `json:"status,omitempty"` |
| 70 | 71 |
Progress *JSONProgress `json:"progressDetail,omitempty"` |
| 71 | 72 |
ProgressMessage string `json:"progress,omitempty"` //deprecated |
| ... | ... |
@@ -87,7 +88,7 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
| 87 | 87 |
if isTerminal {
|
| 88 | 88 |
// <ESC>[2K = erase entire current line |
| 89 | 89 |
fmt.Fprintf(out, "%c[2K\r", 27) |
| 90 |
- endl = "\r\n" |
|
| 90 |
+ endl = "\r" |
|
| 91 | 91 |
} |
| 92 | 92 |
if jm.Time != 0 {
|
| 93 | 93 |
fmt.Fprintf(out, "[%s] ", time.Unix(jm.Time, 0)) |
| ... | ... |
@@ -102,8 +103,10 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
| 102 | 102 |
fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) |
| 103 | 103 |
} else if jm.ProgressMessage != "" { //deprecated
|
| 104 | 104 |
fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) |
| 105 |
+ } else if jm.Stream != "" {
|
|
| 106 |
+ fmt.Fprintf(out, "%s%s", jm.Stream, endl) |
|
| 105 | 107 |
} else {
|
| 106 |
- fmt.Fprintf(out, "%s%s", jm.Status, endl) |
|
| 108 |
+ fmt.Fprintf(out, "%s%s\n", jm.Status, endl) |
|
| 107 | 109 |
} |
| 108 | 110 |
return nil |
| 109 | 111 |
} |
| ... | ... |
@@ -14,6 +14,18 @@ func NewStreamFormatter(json bool) *StreamFormatter {
|
| 14 | 14 |
return &StreamFormatter{json, false}
|
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 |
+func (sf *StreamFormatter) FormatStream(str string) []byte {
|
|
| 18 |
+ sf.used = true |
|
| 19 |
+ if sf.json {
|
|
| 20 |
+ b, err := json.Marshal(&JSONMessage{Stream: str})
|
|
| 21 |
+ if err != nil {
|
|
| 22 |
+ return sf.FormatError(err) |
|
| 23 |
+ } |
|
| 24 |
+ return b |
|
| 25 |
+ } |
|
| 26 |
+ return []byte(str + "\r") |
|
| 27 |
+} |
|
| 28 |
+ |
|
| 17 | 29 |
func (sf *StreamFormatter) FormatStatus(id, format string, a ...interface{}) []byte {
|
| 18 | 30 |
sf.used = true |
| 19 | 31 |
str := fmt.Sprintf(format, a...) |