diff options
author | 2023-01-23 09:25:18 -0800 | |
---|---|---|
committer | 2023-01-23 09:25:18 -0800 | |
commit | 24b0c32c0a0aeabc2131361f9bacaeaec8988ada (patch) | |
tree | 629330cafa35477c87f13398b49260ceb73bfb65 /config.go | |
parent | bdce05d68305442e0214f80b08faf20dd12c0e25 (diff) | |
download | sally-24b0c32c0a0aeabc2131361f9bacaeaec8988ada.tar.gz sally-24b0c32c0a0aeabc2131361f9bacaeaec8988ada.tar.zst sally-24b0c32c0a0aeabc2131361f9bacaeaec8988ada.zip |
config: Don't require packages to be alphabetical (#66)
The configuration parser requries that
entries in the 'packages' section
are in alphabetical order.
It will fail parsing if that's not the case,
even if the configuration is otherwise valid.
This seems like an unnecessary artificial limitation.
Enforcing such a convention should be the user's choice.
This change deletes this limitation.
Diffstat (limited to 'config.go')
-rw-r--r-- | config.go | 35 |
1 files changed, 4 insertions, 31 deletions
@@ -1,16 +1,16 @@ package main import ( - "fmt" "os" - "sort" "strings" yaml "gopkg.in/yaml.v2" ) -const _defaultGodocServer = "pkg.go.dev" -const _defaultBranch = "master" +const ( + _defaultGodocServer = "pkg.go.dev" + _defaultBranch = "master" +) // Config represents the structure of the yaml file type Config struct { @@ -28,29 +28,6 @@ type Package struct { URL string `yaml:"url"` } -// ensureAlphabetical checks that the packages are listed alphabetically in the configuration. -func ensureAlphabetical(data []byte) bool { - // A yaml.MapSlice perservers ordering of keys: https://pkg.go.dev/gopkg.in/yaml.v2#MapSlice - var c struct { - Packages yaml.MapSlice `yaml:"packages"` - } - - if err := yaml.Unmarshal(data, &c); err != nil { - return false - } - - packageNames := make([]string, 0, len(c.Packages)) - for _, v := range c.Packages { - name, ok := v.Key.(string) - if !ok { - return false - } - packageNames = append(packageNames, name) - } - - return sort.StringsAreSorted(packageNames) -} - // Parse takes a path to a yaml file and produces a parsed Config func Parse(path string) (*Config, error) { var c Config @@ -64,10 +41,6 @@ func Parse(path string) (*Config, error) { return nil, err } - if !ensureAlphabetical(data) { - return nil, fmt.Errorf("packages in %s must be alphabetically ordered", path) - } - if c.Godoc.Host == "" { c.Godoc.Host = _defaultGodocServer } else { |