|
@@ -12,6 +12,8 @@ import (
|
|
"github.com/docker/docker/pkg/units"
|
|
"github.com/docker/docker/pkg/units"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+// JSONError wraps a concrete Code and Message, `Code` is
|
|
|
|
+// is a integer error code, `Message` is the error message.
|
|
type JSONError struct {
|
|
type JSONError struct {
|
|
Code int `json:"code,omitempty"`
|
|
Code int `json:"code,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
@@ -21,6 +23,10 @@ func (e *JSONError) Error() string {
|
|
return e.Message
|
|
return e.Message
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// JSONProgress describes a Progress. terminalFd is the fd of the current terminal,
|
|
|
|
+// Start is the initial value for the operation. Current is the current status and
|
|
|
|
+// value of the progress made towards Total. Total is the end value describing when
|
|
|
|
+// we made 100% progress for an operation.
|
|
type JSONProgress struct {
|
|
type JSONProgress struct {
|
|
terminalFd uintptr
|
|
terminalFd uintptr
|
|
Current int64 `json:"current,omitempty"`
|
|
Current int64 `json:"current,omitempty"`
|
|
@@ -76,6 +82,9 @@ func (p *JSONProgress) String() string {
|
|
return pbBox + numbersBox + timeLeftBox
|
|
return pbBox + numbersBox + timeLeftBox
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// JSONMessage defines a message struct. It describes
|
|
|
|
+// the created time, where it from, status, ID of the
|
|
|
|
+// message. It's used for docker events.
|
|
type JSONMessage struct {
|
|
type JSONMessage struct {
|
|
Stream string `json:"stream,omitempty"`
|
|
Stream string `json:"stream,omitempty"`
|
|
Status string `json:"status,omitempty"`
|
|
Status string `json:"status,omitempty"`
|
|
@@ -88,6 +97,9 @@ type JSONMessage struct {
|
|
ErrorMessage string `json:"error,omitempty"` //deprecated
|
|
ErrorMessage string `json:"error,omitempty"` //deprecated
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Display displays the JSONMessage to `out`. `isTerminal` describes if `out`
|
|
|
|
+// is a terminal. If this is the case, it will erase the entire current line
|
|
|
|
+// when dislaying the progressbar.
|
|
func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
|
func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
|
if jm.Error != nil {
|
|
if jm.Error != nil {
|
|
if jm.Error.Code == 401 {
|
|
if jm.Error.Code == 401 {
|
|
@@ -124,6 +136,9 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// DisplayJSONMessagesStream displays a json message stream from `in` to `out`, `isTerminal`
|
|
|
|
+// describes if `out` is a terminal. If this is the case, it will print `\n` at the end of
|
|
|
|
+// each line and move the cursor while displaying.
|
|
func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool) error {
|
|
func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool) error {
|
|
var (
|
|
var (
|
|
dec = json.NewDecoder(in)
|
|
dec = json.NewDecoder(in)
|