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

mlange-42 / modo / 13091969259

01 Feb 2025 08:03PM CUT coverage: 69.922%. Remained the same
13091969259

push

github

web-flow
Add a user guide section on CLI commands (#179)

1439 of 2058 relevant lines covered (69.92%)

24.69 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
        Sources         []string `mapstructure:"source" yaml:"source"`
13
        OutputDir       string   `mapstructure:"output" yaml:"output"`
14
        TestOutput      string   `mapstructure:"tests" yaml:"tests"`
15
        RenderFormat    string   `mapstructure:"format" yaml:"format"`
16
        UseExports      bool     `mapstructure:"exports" yaml:"exports"`
17
        ShortLinks      bool     `mapstructure:"short-links" yaml:"short-links"`
18
        ReportMissing   bool     `mapstructure:"report-missing" yaml:"report-missing"`
19
        Strict          bool     `mapstructure:"strict" yaml:"strict"`
20
        DryRun          bool     `mapstructure:"dry-run" yaml:"dry-run"`
21
        CaseInsensitive bool     `mapstructure:"case-insensitive" yaml:"case-insensitive"`
22
        Bare            bool     `mapstructure:"bare" yaml:"bare"`
23
        TemplateDirs    []string `mapstructure:"templates" yaml:"templates"`
24
        PreRun          []string `mapstructure:"pre-run" yaml:"pre-run"`
25
        PreBuild        []string `mapstructure:"pre-build" yaml:"pre-build"`
26
        PreTest         []string `mapstructure:"pre-test" yaml:"pre-test"`
27
        PostTest        []string `mapstructure:"post-test" yaml:"post-test"`
28
        PostBuild       []string `mapstructure:"post-build" yaml:"post-build"`
29
        PostRun         []string `mapstructure:"post-run" yaml:"post-run"`
30
}
31

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

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

63
func (c *Config) RemovePostScripts() {
×
64
        c.PostTest = nil
×
65
        c.PostBuild = nil
×
66
        c.PostRun = nil
×
67
}
×
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