runInspect inspects the given Swarm config.
(ctx context.Context, dockerCLI command.Cli, opts inspectOptions)
| 44 | |
| 45 | // runInspect inspects the given Swarm config. |
| 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(id string) (any, []byte, error) { |
| 54 | res, err := apiClient.ConfigInspect(ctx, id, client.ConfigInspectOptions{}) |
| 55 | return res.Config, res.Raw, err |
| 56 | } |
| 57 | |
| 58 | // check if the user is trying to apply a template to the pretty format, which |
| 59 | // is not supported |
| 60 | if strings.HasPrefix(opts.format, "pretty") && opts.format != "pretty" { |
| 61 | return errors.New("cannot supply extra formatting options to the pretty template") |
| 62 | } |
| 63 | |
| 64 | configCtx := formatter.Context{ |
| 65 | Output: dockerCLI.Out(), |
| 66 | Format: newFormat(opts.format, false), |
| 67 | } |
| 68 | |
| 69 | if err := inspectFormatWrite(configCtx, opts.names, getRef); err != nil { |
| 70 | return cli.StatusError{StatusCode: 1, Status: err.Error()} |
| 71 | } |
| 72 | return nil |
| 73 | } |
no test coverage detected
searching dependent graphs…