• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 13162005183

05 Feb 2025 04:28PM CUT coverage: 72.707%. Remained the same
13162005183

Pull #206

github

web-flow
Merge 323cbe4df into 30d34556d
Pull Request #206: Fix souce links for packages with upper-case characters

1 of 2 new or added lines in 1 file covered. (50.0%)

1649 of 2268 relevant lines covered (72.71%)

26.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/document/config.go
1
package document
2

3
import (
4
        "fmt"
5
        "reflect"
6
        "strings"
7

8
        "github.com/spf13/viper"
9
)
10

11
type Config struct {
12
        InputFiles      []string          `mapstructure:"input" yaml:"input"`
13
        Sources         []string          `mapstructure:"source" yaml:"source"`
14
        SourceURLs      map[string]string `mapstructure:"source-url" yaml:"source-url"`
15
        OutputDir       string            `mapstructure:"output" yaml:"output"`
16
        TestOutput      string            `mapstructure:"tests" yaml:"tests"`
17
        RenderFormat    string            `mapstructure:"format" yaml:"format"`
18
        UseExports      bool              `mapstructure:"exports" yaml:"exports"`
19
        ShortLinks      bool              `mapstructure:"short-links" yaml:"short-links"`
20
        ReportMissing   bool              `mapstructure:"report-missing" yaml:"report-missing"`
21
        Strict          bool              `mapstructure:"strict" yaml:"strict"`
22
        DryRun          bool              `mapstructure:"dry-run" yaml:"dry-run"`
23
        CaseInsensitive bool              `mapstructure:"case-insensitive" yaml:"case-insensitive"`
24
        Bare            bool              `mapstructure:"bare" yaml:"bare"`
25
        TemplateDirs    []string          `mapstructure:"templates" yaml:"templates"`
26
        PreRun          []string          `mapstructure:"pre-run" yaml:"pre-run"`
27
        PreBuild        []string          `mapstructure:"pre-build" yaml:"pre-build"`
28
        PreTest         []string          `mapstructure:"pre-test" yaml:"pre-test"`
29
        PostTest        []string          `mapstructure:"post-test" yaml:"post-test"`
30
        PostBuild       []string          `mapstructure:"post-build" yaml:"post-build"`
31
        PostRun         []string          `mapstructure:"post-run" yaml:"post-run"`
32
}
33

34
func ConfigFromViper(v *viper.Viper) (*Config, error) {
×
35
        c := Config{}
×
36
        if err := v.Unmarshal(&c); err != nil {
×
37
                return nil, err
×
38
        }
×
39
        if err := c.check(v); err != nil {
×
40
                return nil, err
×
41
        }
×
42
        return &c, nil
×
43
}
44

45
func (c *Config) check(v *viper.Viper) error {
×
46
        fields := map[string]bool{}
×
47
        tp := reflect.TypeOf(c).Elem()
×
48
        for i := range tp.NumField() {
×
49
                field := tp.Field(i)
×
50
                if tag, ok := field.Tag.Lookup("mapstructure"); ok {
×
51
                        if _, ok := fields[tag]; ok {
×
52
                                return fmt.Errorf("duplicate field name '%s'", tag)
×
53
                        }
×
54
                        fields[tag] = true
×
55
                }
56
        }
57
        for _, key := range v.AllKeys() {
×
58
                parts := strings.Split(key, ".")
×
59
                if _, ok := fields[parts[0]]; !ok {
×
60
                        return fmt.Errorf("unknown field '%s' in config file", key)
×
61
                }
×
62
        }
63
        return nil
×
64
}
65

66
func (c *Config) RemovePostScripts() {
×
67
        c.PostTest = nil
×
68
        c.PostBuild = nil
×
69
        c.PostRun = nil
×
70
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc