(ctx context.Context, dockerCLI command.Cli, opts inspectOptions)
| 44 | } |
| 45 | |
| 46 | func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error { |
| 47 | apiClient := dockerCLI.Client() |
| 48 | |
| 49 | if opts.pretty { |
| 50 | opts.format = "pretty" |
| 51 | } |
| 52 | |
| 53 | getRef := func(ref string) (any, []byte, error) { |
| 54 | nodeRef, err := Reference(ctx, apiClient, ref) |
| 55 | if err != nil { |
| 56 | return nil, nil, err |
| 57 | } |
| 58 | res, err := apiClient.NodeInspect(ctx, nodeRef, client.NodeInspectOptions{}) |
| 59 | return res.Node, res.Raw, err |
| 60 | } |
| 61 | |
| 62 | // check if the user is trying to apply a template to the pretty format, which |
| 63 | // is not supported |
| 64 | if strings.HasPrefix(opts.format, "pretty") && opts.format != "pretty" { |
| 65 | return errors.New("cannot supply extra formatting options to the pretty template") |
| 66 | } |
| 67 | |
| 68 | nodeCtx := formatter.Context{ |
| 69 | Output: dockerCLI.Out(), |
| 70 | Format: newFormat(opts.format, false), |
| 71 | } |
| 72 | |
| 73 | if err := inspectFormatWrite(nodeCtx, opts.nodeIds, getRef); err != nil { |
| 74 | return cli.StatusError{StatusCode: 1, Status: err.Error()} |
| 75 | } |
| 76 | return nil |
| 77 | } |
no test coverage detected
searching dependent graphs…