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

mlange-42 / modo / 13074745779

31 Jan 2025 02:29PM CUT coverage: 67.728%. Remained the same
13074745779

Pull #171

github

web-flow
Merge 27bb17a6a into 82e1dee76
Pull Request #171: Show full sources of example package

1213 of 1791 relevant lines covered (67.73%)

28.13 hits per line

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

0.0
/document/config.go
1
package document
2

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

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

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

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

42
func (c *Config) check(v *viper.Viper) error {
×
43
        fields := map[string]bool{}
×
44
        tp := reflect.TypeOf(c).Elem()
×
45
        for i := range tp.NumField() {
×
46
                field := tp.Field(i)
×
47
                if tag, ok := field.Tag.Lookup("mapstructure"); ok {
×
48
                        if _, ok := fields[tag]; ok {
×
49
                                return fmt.Errorf("duplicate field name '%s'", tag)
×
50
                        }
×
51
                        fields[tag] = true
×
52
                }
53
        }
54
        for _, key := range v.AllKeys() {
×
55
                if _, ok := fields[key]; !ok {
×
56
                        return fmt.Errorf("unknown field '%s' in config file", key)
×
57
                }
×
58
        }
59
        return nil
×
60
}
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