Skip to content

Commit 18178e0

Browse files
authored
Merge pull request #5981 from thaJeztah/remove_ContextType
context list: remove temporary ContextType from JSON output
2 parents e937b52 + cda7235 commit 18178e0

File tree

3 files changed

+5
-51
lines changed

3 files changed

+5
-51
lines changed

cli/command/context/list.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
6969
Name: rawMeta.Name,
7070
Current: isCurrent,
7171
Error: err.Error(),
72-
73-
ContextType: getContextType(nil, opts.format),
7472
})
7573
continue
7674
}
@@ -85,8 +83,6 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
8583
Description: meta.Description,
8684
DockerEndpoint: dockerEndpoint.Host,
8785
Error: errMsg,
88-
89-
ContextType: getContextType(meta.AdditionalFields, opts.format),
9086
}
9187
contexts = append(contexts, &desc)
9288
}
@@ -103,8 +99,6 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
10399
Name: curContext,
104100
Current: true,
105101
Error: errMsg,
106-
107-
ContextType: getContextType(nil, opts.format),
108102
})
109103
}
110104
sort.Slice(contexts, func(i, j int) bool {
@@ -120,30 +114,6 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
120114
return nil
121115
}
122116

123-
// getContextType sets the LegacyContextType field for compatibility with
124-
// Visual Studio, which depends on this field from the "cloud integration"
125-
// wrapper.
126-
//
127-
// https://github.com/docker/compose-cli/blob/c156ce6da4c2b317174d42daf1b019efa87e9f92/api/context/store/contextmetadata.go#L28-L34
128-
// https://github.com/docker/compose-cli/blob/c156ce6da4c2b317174d42daf1b019efa87e9f92/api/context/store/store.go#L34-L51
129-
//
130-
// TODO(thaJeztah): remove this and [ClientContext.ContextType] once Visual Studio is updated to no longer depend on this.
131-
func getContextType(meta map[string]any, format string) string {
132-
if format != formatter.JSONFormat && format != formatter.JSONFormatKey {
133-
// We only need the ContextType field when formatting as JSON,
134-
// which is the format-string used by Visual Studio to detect the
135-
// context-type.
136-
return ""
137-
}
138-
if ct, ok := meta["Type"]; ok {
139-
// If the context on-disk has a context-type (ecs, aci), return it.
140-
return ct.(string)
141-
}
142-
143-
// Use the default context-type.
144-
return "moby"
145-
}
146-
147117
func format(dockerCli command.Cli, opts *listOptions, contexts []*formatter.ClientContext) error {
148118
contextCtx := formatter.Context{
149119
Output: dockerCli.Out(),
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{"Name":"context1","Description":"description of context1","DockerEndpoint":"https://someswarmserver.example.com","Current":false,"Error":"","ContextType":"aci"}
2-
{"Name":"context2","Description":"description of context2","DockerEndpoint":"https://someswarmserver.example.com","Current":false,"Error":"","ContextType":"ecs"}
3-
{"Name":"context3","Description":"description of context3","DockerEndpoint":"https://someswarmserver.example.com","Current":false,"Error":"","ContextType":"moby"}
4-
{"Name":"current","Description":"description of current","DockerEndpoint":"https://someswarmserver.example.com","Current":true,"Error":"","ContextType":"moby"}
5-
{"Name":"default","Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"unix:///var/run/docker.sock","Current":false,"Error":"","ContextType":"moby"}
1+
{"Current":false,"Description":"description of context1","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"context1"}
2+
{"Current":false,"Description":"description of context2","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"context2"}
3+
{"Current":false,"Description":"description of context3","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"context3"}
4+
{"Current":true,"Description":"description of current","DockerEndpoint":"https://someswarmserver.example.com","Error":"","Name":"current"}
5+
{"Current":false,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"unix:///var/run/docker.sock","Error":"","Name":"default"}

cli/command/formatter/context.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package formatter
22

3-
import "encoding/json"
4-
53
const (
64
// ClientContextTableFormat is the default client context format.
75
ClientContextTableFormat = "table {{.Name}}{{if .Current}} *{{end}}\t{{.Description}}\t{{.DockerEndpoint}}\t{{.Error}}"
@@ -30,13 +28,6 @@ type ClientContext struct {
3028
DockerEndpoint string
3129
Current bool
3230
Error string
33-
34-
// ContextType is a temporary field for compatibility with
35-
// Visual Studio, which depends on this from the "cloud integration"
36-
// wrapper.
37-
//
38-
// Deprecated: this type is only for backward-compatibility. Do not use.
39-
ContextType string `json:"ContextType,omitempty"`
4031
}
4132

4233
// ClientContextWrite writes formatted contexts using the Context
@@ -69,13 +60,6 @@ func newClientContextContext() *clientContextContext {
6960
}
7061

7162
func (c *clientContextContext) MarshalJSON() ([]byte, error) {
72-
if c.c.ContextType != "" {
73-
// We only have ContextType set for plain "json" or "{{json .}}" formatting,
74-
// so we should be able to just use the default json.Marshal with no
75-
// special handling.
76-
return json.Marshal(c.c)
77-
}
78-
// FIXME(thaJeztah): why do we need a special marshal function here?
7963
return MarshalJSON(c)
8064
}
8165

0 commit comments

Comments
 (0)