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

mlange-42 / modo / 12999379643

27 Jan 2025 10:16PM CUT coverage: 65.591%. Remained the same
12999379643

push

github

web-flow
Use Hugo fork with Mojo lexer for docs (#132)

1098 of 1674 relevant lines covered (65.59%)

31.25 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
        Strict          bool     `mapstructure:"strict" yaml:"strict"`
18
        DryRun          bool     `mapstructure:"dry-run" yaml:"dry-run"`
19
        CaseInsensitive bool     `mapstructure:"case-insensitive" yaml:"case-insensitive"`
20
        Bare            bool     `mapstructure:"bare" yaml:"bare"`
21
        TemplateDirs    []string `mapstructure:"templates" yaml:"templates"`
22
        PreRun          []string `mapstructure:"pre-run" yaml:"pre-run"`
23
        PreBuild        []string `mapstructure:"pre-build" yaml:"pre-build"`
24
        PreTest         []string `mapstructure:"pre-test" yaml:"pre-test"`
25
        PostTest        []string `mapstructure:"post-test" yaml:"post-test"`
26
        PostBuild       []string `mapstructure:"post-build" yaml:"post-build"`
27
        PostRun         []string `mapstructure:"post-run" yaml:"post-run"`
28
}
29

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

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