Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 3a77039

Browse files
committed
ref: use plugins part of config file
To avoid any conflict with the CLI, use the `plugins` section of the config. This section is read and saved by the CLI without the risk to remove the value in there. So it's a safe way to deal with this feature. As it's a cross plugin configuration (now for scout but goal is wider than that) then put it under a generic `cliHints` name so that other plugins might use it if needed. Signed-off-by: Yves Brissaud <[email protected]>
1 parent fac770a commit 3a77039

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

api/config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ func configFilePath(dir string) string {
100100

101101
// File contains the current context from the docker configuration file
102102
type File struct {
103-
CurrentContext string `json:"currentContext,omitempty"`
104-
CliHints *bool `json:"cliHints,omitempty"`
103+
CurrentContext string `json:"currentContext,omitempty"`
104+
Plugins map[string]map[string]string `json:"plugins,omitempty"`
105105
}

cli/mobycli/cli_hints.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import (
2626
const (
2727
cliHintsEnvVarName = "DOCKER_CLI_HINTS"
2828
cliHintsDefaultBehaviour = true
29+
30+
cliHintsPluginName = "cliHints"
31+
cliHintsEnabledName = "enabled"
2932
)
3033

3134
func CliHintsEnabled() bool {
@@ -40,8 +43,12 @@ func CliHintsEnabled() bool {
4043
// can't read the config file, use the default behaviour
4144
return cliHintsDefaultBehaviour
4245
}
43-
if conf.CliHints != nil {
44-
return *conf.CliHints
46+
if cliHintsPluginConfig, ok := conf.Plugins[cliHintsPluginName]; ok {
47+
if cliHintsValue, ok := cliHintsPluginConfig[cliHintsEnabledName]; ok {
48+
if cliHints, err := strconv.ParseBool(cliHintsValue); err == nil {
49+
return cliHints
50+
}
51+
}
4552
}
4653

4754
return cliHintsDefaultBehaviour

cli/mobycli/cli_hints_test.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ func TestCliHintsEnabled(t *testing.T) {
6666
},
6767
true,
6868
},
69+
{
70+
"plugin defined in config file but no enabled entry",
71+
func() {
72+
d := testConfigDir(t)
73+
writeSampleConfig(t, d, configPartial)
74+
},
75+
true,
76+
},
6977
{
7078
"disabled in config file",
7179
func() {
@@ -120,9 +128,24 @@ func writeSampleConfig(t *testing.T, d string, conf []byte) {
120128
}
121129

122130
var configEnabled = []byte(`{
123-
"cliHints": true
131+
"plugins": {
132+
"cliHints": {
133+
"enabled": "true"
134+
}
135+
}
124136
}`)
125137

126138
var configDisabled = []byte(`{
127-
"cliHints": false
139+
"plugins": {
140+
"cliHints": {
141+
"enabled": "false"
142+
}
143+
}
144+
}`)
145+
146+
var configPartial = []byte(`{
147+
"plugins": {
148+
"cliHints": {
149+
}
150+
}
128151
}`)

0 commit comments

Comments
 (0)