-
Notifications
You must be signed in to change notification settings - Fork 91
Closed
Description
Now, we run resolveConfig
to do configtest and detect Invalid syntax (config_test.go shows that).
But, we can't detect unexpected key, so I want to improve by using Undecoded().
It would be better if it could suggest intended key.
This is sample of mackerel-agent.conf
which includes unexpected key.
1 apikey = "abcdefg"
2 podfile = "/path/to/pidfile"
3
4 [foo]
5 command = "bar"
6
7 [plugins.checks.foo]
8 command = "bar"
9
10 [plugin.check.foo]
11 command = "bar"
Actual behavior
$ mackerel-agent configtest
/path/to/mackerel-agent.conf Syntax OK
Expected behavior
$ mackerel-agent configtest
warn: podfile is invalid key. Do you mean pidfile ?(line 2)
warn: foo is invalid key (line 4)
warn: plugins.checks.foo is invalid key. Do you mean plugin.checks.foo ? (line 7)
warn: plugin.check.foo is invalid key. Do you mean plugin.checks.foo ? (line 10)
Implementation image
Create config/validate.go#ValidateConfigFile
and use it in commands.go#doConfigtest
func doConfigtest(fs *flag.FlagSet, argv []string) error {
conf, err := resolveConfig(fs, argv)
if err != nil {
return fmt.Errorf("failed to test config: %s", err)
}
warnings := config.ValidateConfigFile(conf.Conffile)
if warnings != nil {
return <display warnings>
}
fmt.Fprintf(os.Stderr, "%s Syntax OK\n", conf.Conffile)
return nil
}
Implementation stage
- detect unexpected key Improve
mackerel-agent configtest
: detect unexpected key #813 - show suggestion Improve
mackerel-agent configtest
: Add suggestion to unexpected keys #818
lufia
Metadata
Metadata
Assignees
Labels
No labels