mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 13:11:30 +00:00
Merge branch 'master' into 0.6.5-dm-plugin
This commit is contained in:
+24
-11
@@ -779,14 +779,19 @@ func NewHTTPRequestError(msg string, res *http.Response) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (jm *JSONMessage) Display(out io.Writer) error {
|
||||
func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
|
||||
if jm.Error != nil {
|
||||
if jm.Error.Code == 401 {
|
||||
return fmt.Errorf("Authentication is required.")
|
||||
}
|
||||
return jm.Error
|
||||
}
|
||||
fmt.Fprintf(out, "%c[2K\r", 27)
|
||||
endl := ""
|
||||
if isTerminal {
|
||||
// <ESC>[2K = erase entire current line
|
||||
fmt.Fprintf(out, "%c[2K\r", 27)
|
||||
endl = "\r"
|
||||
}
|
||||
if jm.Time != 0 {
|
||||
fmt.Fprintf(out, "[%s] ", time.Unix(jm.Time, 0))
|
||||
}
|
||||
@@ -797,14 +802,14 @@ func (jm *JSONMessage) Display(out io.Writer) error {
|
||||
fmt.Fprintf(out, "(from %s) ", jm.From)
|
||||
}
|
||||
if jm.Progress != "" {
|
||||
fmt.Fprintf(out, "%s %s\r", jm.Status, jm.Progress)
|
||||
fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress, endl)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\r\n", jm.Status)
|
||||
fmt.Fprintf(out, "%s%s\n", jm.Status, endl)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DisplayJSONMessagesStream(in io.Reader, out io.Writer) error {
|
||||
func DisplayJSONMessagesStream(in io.Reader, out io.Writer, isTerminal bool) error {
|
||||
dec := json.NewDecoder(in)
|
||||
ids := make(map[string]int)
|
||||
diff := 0
|
||||
@@ -825,11 +830,17 @@ func DisplayJSONMessagesStream(in io.Reader, out io.Writer) error {
|
||||
} else {
|
||||
diff = len(ids) - line
|
||||
}
|
||||
fmt.Fprintf(out, "%c[%dA", 27, diff)
|
||||
if isTerminal {
|
||||
// <ESC>[{diff}A = move cursor up diff rows
|
||||
fmt.Fprintf(out, "%c[%dA", 27, diff)
|
||||
}
|
||||
}
|
||||
err := jm.Display(out)
|
||||
err := jm.Display(out, isTerminal)
|
||||
if jm.ID != "" {
|
||||
fmt.Fprintf(out, "%c[%dB", 27, diff)
|
||||
if isTerminal {
|
||||
// <ESC>[{diff}B = move cursor down diff rows
|
||||
fmt.Fprintf(out, "%c[%dB", 27, diff)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1226,12 +1237,14 @@ func IsClosedError(err error) bool {
|
||||
|
||||
func PartParser(template, data string) (map[string]string, error) {
|
||||
// ip:public:private
|
||||
templateParts := strings.Split(template, ":")
|
||||
parts := strings.Split(data, ":")
|
||||
var (
|
||||
templateParts = strings.Split(template, ":")
|
||||
parts = strings.Split(data, ":")
|
||||
out = make(map[string]string, len(templateParts))
|
||||
)
|
||||
if len(parts) != len(templateParts) {
|
||||
return nil, fmt.Errorf("Invalid format to parse. %s should match template %s", data, template)
|
||||
}
|
||||
out := make(map[string]string, len(templateParts))
|
||||
|
||||
for i, t := range templateParts {
|
||||
value := ""
|
||||
|
||||
Reference in New Issue
Block a user