func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { client := dockerCli.Client() ctx := context.Background() getRef := func(ref string) (interface{}, []byte, error) { service, _, err := client.ServiceInspectWithRaw(ctx, ref) if err == nil || !apiclient.IsErrServiceNotFound(err) { return service, nil, err } return nil, nil, fmt.Errorf("Error: no such service: %s", ref) } if !opts.pretty { return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRef) } return printHumanFriendly(dockerCli.Out(), opts.refs, getRef) }
func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { client := dockerCli.Client() ctx := context.Background() if opts.pretty { opts.format = "pretty" } getRef := func(ref string) (interface{}, []byte, error) { service, _, err := client.ServiceInspectWithRaw(ctx, ref) if err == nil || !apiclient.IsErrServiceNotFound(err) { return service, nil, err } return nil, nil, fmt.Errorf("Error: no such service: %s", ref) } f := opts.format if len(f) == 0 { f = "raw" if len(dockerCli.ConfigFile().ServiceInspectFormat) > 0 { f = dockerCli.ConfigFile().ServiceInspectFormat } } // check if the user is trying to apply a template to the pretty format, which // is not supported if strings.HasPrefix(f, "pretty") && f != "pretty" { return fmt.Errorf("Cannot supply extra formatting options to the pretty template") } serviceCtx := formatter.Context{ Output: dockerCli.Out(), Format: formatter.NewServiceFormat(f), } if err := formatter.ServiceInspectWrite(serviceCtx, opts.refs, getRef); err != nil { return cli.StatusError{StatusCode: 1, Status: err.Error()} } return nil }