11package formatter
22
3- import (
4- "github.com/docker/cli/cli/command/formatter"
5- )
6-
73const (
84 // ClientContextTableFormat is the default client context format
95 ClientContextTableFormat = "table {{.NameWithCurrent}}\t {{.Description}}\t {{.DockerEndpoint}}\t {{.KubernetesEndpoint}}\t {{.StackOrchestrator}}"
@@ -13,6 +9,14 @@ const (
139 stackOrchestrastorHeader = "ORCHESTRATOR"
1410)
1511
12+ // NewClientContextFormat returns a Format for rendering using a Context
13+ func NewClientContextFormat (source string ) Format {
14+ if source == TableFormatKey {
15+ return Format (ClientContextTableFormat )
16+ }
17+ return Format (source )
18+ }
19+
1620// ClientContext is a context for display
1721type ClientContext struct {
1822 Name string
@@ -24,8 +28,8 @@ type ClientContext struct {
2428}
2529
2630// ClientContextWrite writes formatted contexts using the Context
27- func ClientContextWrite (ctx formatter. Context , contexts []* ClientContext ) error {
28- render := func (format func (subContext formatter. SubContext ) error ) error {
31+ func ClientContextWrite (ctx Context , contexts []* ClientContext ) error {
32+ render := func (format func (subContext SubContext ) error ) error {
2933 for _ , context := range contexts {
3034 if err := format (& clientContextContext {c : context }); err != nil {
3135 return err
@@ -37,15 +41,15 @@ func ClientContextWrite(ctx formatter.Context, contexts []*ClientContext) error
3741}
3842
3943type clientContextContext struct {
40- formatter. HeaderContext
44+ HeaderContext
4145 c * ClientContext
4246}
4347
4448func newClientContextContext () * clientContextContext {
4549 ctx := clientContextContext {}
46- ctx .Header = formatter. SubHeaderContext {
47- "NameWithCurrent" : formatter . NameHeader ,
48- "Description" : formatter . DescriptionHeader ,
50+ ctx .Header = SubHeaderContext {
51+ "NameWithCurrent" : NameHeader ,
52+ "Description" : DescriptionHeader ,
4953 "DockerEndpoint" : dockerEndpointHeader ,
5054 "KubernetesEndpoint" : kubernetesEndpointHeader ,
5155 "StackOrchestrator" : stackOrchestrastorHeader ,
@@ -54,7 +58,7 @@ func newClientContextContext() *clientContextContext {
5458}
5559
5660func (c * clientContextContext ) MarshalJSON () ([]byte , error ) {
57- return formatter . MarshalJSON (c )
61+ return MarshalJSON (c )
5862}
5963
6064func (c * clientContextContext ) NameWithCurrent () string {
0 commit comments