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

mlange-42 / modo / 12856850930

19 Jan 2025 08:18PM CUT coverage: 57.843% (-1.4%) from 59.246%
12856850930

push

github

web-flow
Add CLI flag `--dry-run` for no file output (#71)

8 of 66 new or added lines in 4 files covered. (12.12%)

12 existing lines in 3 files now uncovered.

826 of 1428 relevant lines covered (57.84%)

7.68 hits per line

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

79.66
/document/processor.go
1
package document
2

3
import (
4
        "fmt"
5
        "log"
6
        "os"
7
        "strings"
8
        "text/template"
9
)
10

11
type Config struct {
12
        InputFile       string
13
        OutputDir       string
14
        TemplateDirs    []string
15
        UseExports      bool
16
        ShortLinks      bool
17
        CaseInsensitive bool
18
        Strict          bool
19
        DryRun          bool
20
}
21

22
type Processor struct {
23
        Config      *Config
24
        Template    *template.Template
25
        Formatter   Formatter
26
        Docs        *Docs
27
        ExportDocs  *Docs
28
        allPaths    map[string]bool
29
        linkTargets map[string]elemPath
30
        linkExports map[string]string
31
        writer      func(file, text string) error
32
}
33

34
func NewProcessor(docs *Docs, f Formatter, t *template.Template, config *Config) *Processor {
8✔
35
        return NewProcessorWithWriter(docs, f, t, config, func(file, text string) error {
8✔
36
                return os.WriteFile(file, []byte(text), 0666)
×
37
        })
×
38
}
39

40
func NewProcessorWithWriter(docs *Docs, f Formatter, t *template.Template, config *Config, writer func(file, text string) error) *Processor {
12✔
41
        return &Processor{
12✔
42
                Config:    config,
12✔
43
                Template:  t,
12✔
44
                Formatter: f,
12✔
45
                Docs:      docs,
12✔
46
                writer:    writer,
12✔
47
        }
12✔
48
}
12✔
49

50
// PrepareDocs processes the API docs for subsequent rendering.
51
func (proc *Processor) PrepareDocs() error {
4✔
52
        // Collect the paths of all (sub)-elements in the original structure.
4✔
53
        proc.collectElementPaths()
4✔
54
        // Re-structure according to exports.
4✔
55
        err := proc.filterPackages()
4✔
56
        if err != nil {
4✔
57
                return err
×
58
        }
×
59
        // Collect all link target paths.
60
        proc.collectPaths()
4✔
61
        if !proc.Config.UseExports {
7✔
62
                for k := range proc.linkTargets {
16✔
63
                        proc.linkExports[k] = k
13✔
64
                }
13✔
65
        }
66
        // Replaces cross-refs by placeholders.
67
        if err := proc.processLinksPackage(proc.Docs.Decl, []string{}); err != nil {
4✔
68
                return err
×
69
        }
×
70
        return nil
4✔
71
}
72

73
func (proc *Processor) WriteFile(file, text string) error {
15✔
74
        return proc.writer(file, text)
15✔
75
}
15✔
76

77
func (proc *Processor) warnOrError(pattern string, args ...any) error {
14✔
78
        if proc.Config.Strict {
14✔
79
                return fmt.Errorf(pattern, args...)
×
80
        }
×
81
        log.Printf("WARNING: "+pattern+"\n", args...)
14✔
82
        return nil
14✔
83
}
84

85
func (proc *Processor) addLinkExport(oldPath, newPath []string) {
28✔
86
        proc.linkExports[strings.Join(oldPath, ".")] = strings.Join(newPath, ".")
28✔
87
}
28✔
88

89
func (proc *Processor) addLinkTarget(elPath, filePath []string, kind string, isSection bool) {
34✔
90
        proc.linkTargets[strings.Join(elPath, ".")] = elemPath{Elements: filePath, Kind: kind, IsSection: isSection}
34✔
91
}
34✔
92

93
func (proc *Processor) addElementPath(elPath, filePath []string, kind string, isSection bool) {
24✔
94
        if isSection {
32✔
95
                return
8✔
96
        }
8✔
97
        proc.allPaths[strings.Join(elPath, ".")] = true
16✔
98
        _, _ = filePath, kind
16✔
99
}
100

101
func (proc *Processor) mkDirs(path string) error {
8✔
102
        if proc.Config.DryRun {
8✔
NEW
103
                return nil
×
NEW
104
        }
×
105
        if err := os.MkdirAll(path, os.ModePerm); err != nil && !os.IsExist(err) {
8✔
NEW
106
                return err
×
NEW
107
        }
×
108
        return nil
8✔
109
}
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