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

mlange-42 / modo / 12809088497

16 Jan 2025 12:40PM CUT coverage: 36.785% (+2.0%) from 34.803%
12809088497

Pull #42

github

web-flow
Merge d95183431 into e9d148681
Pull Request #42: Implement re-exports on package level

235 of 493 new or added lines in 11 files covered. (47.67%)

41 existing lines in 4 files now uncovered.

437 of 1188 relevant lines covered (36.78%)

2.67 hits per line

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

0.0
/main.go
1
package main
2

3
import (
4
        "fmt"
5
        "io"
6
        "log"
7
        "os"
8

9
        "github.com/mlange-42/modo/document"
10
        "github.com/mlange-42/modo/format"
11
        "github.com/spf13/cobra"
12
)
13

14
func main() {
×
15
        if err := rootCommand().Execute(); err != nil {
×
16
                log.Fatal(err)
×
17
        }
×
18
}
19

20
type args struct {
21
        file            string
22
        renderFormat    string
23
        caseInsensitive bool
24
        useExports      bool
25
        shortLinks      bool
26
        outDir          string
27
}
28

29
func rootCommand() *cobra.Command {
×
30
        var cliArgs args
×
31

×
32
        root := &cobra.Command{
×
33
                Use:   "modo OUT-PATH",
×
34
                Short: "Mojo documentation generator",
×
35
                Long:  ``,
×
36
                Args:  cobra.ExactArgs(1),
×
37
                RunE: func(cmd *cobra.Command, args []string) error {
×
38
                        cliArgs.outDir = args[0]
×
39
                        return run(&cliArgs)
×
40
                },
×
41
        }
42

43
        root.Flags().StringVarP(&cliArgs.file, "input", "i", "", "File to read. Reads from STDIN if not specified.")
×
44
        root.Flags().StringVarP(&cliArgs.renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
NEW
45
        root.Flags().BoolVarP(&cliArgs.useExports, "exports", "e", false, "Process according to 'Exports:' directives in packages.")
×
46
        root.Flags().BoolVar(&cliArgs.shortLinks, "short-links", false, "Renders shortened link labels, stripping packages and modules.")
×
47
        root.Flags().BoolVar(&cliArgs.caseInsensitive, "case-insensitive", false, "Build for systems that are not case-sensitive regarding file names.\nAppends hyphen (-) to capitalized file names.")
×
48

×
49
        root.Flags().SortFlags = false
×
50

×
51
        return root
×
52
}
53

54
func run(args *args) error {
×
55
        if args.outDir == "" {
×
56
                return fmt.Errorf("no output path given")
×
57
        }
×
58

59
        data, err := read(args.file)
×
60
        if err != nil {
×
61
                return err
×
62
        }
×
63

64
        docs, err := document.FromJson(data)
×
65
        if err != nil {
×
66
                return err
×
67
        }
×
68

69
        rFormat, err := format.GetFormat(args.renderFormat)
×
70
        if err != nil {
×
71
                return err
×
72
        }
×
73
        if args.caseInsensitive {
×
74
                document.CaseSensitiveSystem = false
×
75
        }
×
76

NEW
77
        err = format.Render(docs, args.outDir, rFormat, args.useExports, args.shortLinks)
×
78
        if err != nil {
×
79
                return err
×
80
        }
×
81

82
        return nil
×
83
}
84

85
func read(file string) ([]byte, error) {
×
86
        if file == "" {
×
87
                return io.ReadAll(os.Stdin)
×
88
        } else {
×
89
                return os.ReadFile(file)
×
90
        }
×
91
}
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