MCPcopy Index your code
hub / github.com/docker/cli / runInspect

Function runInspect

cli/command/service/inspect.go:53–100  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts inspectOptions)

Source from the content-addressed store, hash-verified

51}
52
53func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
54 apiClient := dockerCLI.Client()
55
56 if opts.pretty {
57 opts.format = "pretty"
58 }
59
60 getRef := func(ref string) (any, []byte, error) {
61 // Service inspect shows defaults values in empty fields.
62 res, err := apiClient.ServiceInspect(ctx, ref, client.ServiceInspectOptions{InsertDefaults: true})
63 if err == nil || !errdefs.IsNotFound(err) {
64 return res.Service, res.Raw, err
65 }
66 return nil, nil, fmt.Errorf("no such service: %s", ref)
67 }
68
69 getNetwork := func(ref string) (any, []byte, error) {
70 res, err := apiClient.NetworkInspect(ctx, ref, client.NetworkInspectOptions{Scope: "swarm"})
71 if err == nil || !errdefs.IsNotFound(err) {
72 return res.Network, res.Raw, err
73 }
74 return nil, nil, fmt.Errorf("no such network: %s", ref)
75 }
76
77 f := opts.format
78 if len(f) == 0 {
79 f = "raw"
80 if len(dockerCLI.ConfigFile().ServiceInspectFormat) > 0 {
81 f = dockerCLI.ConfigFile().ServiceInspectFormat
82 }
83 }
84
85 // check if the user is trying to apply a template to the pretty format, which
86 // is not supported
87 if strings.HasPrefix(f, "pretty") && f != "pretty" {
88 return errors.New("cannot supply extra formatting options to the pretty template")
89 }
90
91 serviceCtx := formatter.Context{
92 Output: dockerCLI.Out(),
93 Format: newFormat(f),
94 }
95
96 if err := inspectFormatWrite(serviceCtx, opts.refs, getRef, getNetwork); err != nil {
97 return cli.StatusError{StatusCode: 1, Status: err.Error()}
98 }
99 return nil
100}

Callers 1

newInspectCommandFunction · 0.70

Calls 8

newFormatFunction · 0.70
inspectFormatWriteFunction · 0.70
ClientMethod · 0.65
ConfigFileMethod · 0.65
OutMethod · 0.65
ServiceInspectMethod · 0.45
NetworkInspectMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…