addServerInfo retrieves the server information and adds it to the dockerInfo struct. if a connection error occurs, it will be returned as an error. other errors are appended to the info.ServerErrors field.
(ctx context.Context, dockerCli command.Cli, format string, info *dockerInfo)
| 117 | // if a connection error occurs, it will be returned as an error. |
| 118 | // other errors are appended to the info.ServerErrors field. |
| 119 | func addServerInfo(ctx context.Context, dockerCli command.Cli, format string, info *dockerInfo) error { |
| 120 | res, err := dockerCli.Client().Info(ctx, client.InfoOptions{}) |
| 121 | if err != nil { |
| 122 | // if no format is provided and we have an error, don't print the server info |
| 123 | if format == "" { |
| 124 | info.Info = nil |
| 125 | } |
| 126 | if !client.IsErrConnectionFailed(err) { |
| 127 | info.ServerErrors = append(info.ServerErrors, err.Error()) |
| 128 | if format != "" { |
| 129 | // if a format is provided, print the error, as it may be hidden |
| 130 | // if the format template doesn't include the ServerErrors field. |
| 131 | fprintln(dockerCli.Err(), err) |
| 132 | } |
| 133 | return nil |
| 134 | } |
| 135 | // on a server connection error, we want to return an error |
| 136 | return err |
| 137 | } |
| 138 | |
| 139 | // only assign the server info if we have no error |
| 140 | info.Info = &res.Info |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | // placeHolders does a rudimentary match for possible placeholders in a |
| 145 | // template, matching a '.', followed by an letter (a-z/A-Z). |