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

mlange-42 / modo / 12810176069

16 Jan 2025 01:43PM CUT coverage: 36.569% (+1.8%) from 34.803%
12810176069

push

github

web-flow
Implement re-exports on package level (#42)

235 of 505 new or added lines in 11 files covered. (46.53%)

41 existing lines in 4 files now uncovered.

437 of 1195 relevant lines covered (36.57%)

2.65 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",
×
NEW
34
                Short: "Modo -- DocGen for Mojo.",
×
NEW
35
                Long: `Modo -- DocGen for Mojo.
×
NEW
36

×
NEW
37
Modo generates Markdown for static site generators (SSGs) from 'mojo doc' JSON output.
×
NEW
38

×
NEW
39
Usage:
×
NEW
40
  modo docs -i docs.json        # from a file
×
NEW
41
  mojo doc ./src | modo docs    # from 'mojo doc'
×
NEW
42
`,
×
NEW
43
                Args: cobra.ExactArgs(1),
×
44
                RunE: func(cmd *cobra.Command, args []string) error {
×
45
                        cliArgs.outDir = args[0]
×
46
                        return run(&cliArgs)
×
47
                },
×
48
        }
49

NEW
50
        root.Flags().StringVarP(&cliArgs.file, "input", "i", "", "'mojo doc' JSON file to process. Reads from STDIN if not specified.")
×
51
        root.Flags().StringVarP(&cliArgs.renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
NEW
52
        root.Flags().BoolVarP(&cliArgs.useExports, "exports", "e", false, "Process according to 'Exports:' sections in packages.")
×
NEW
53
        root.Flags().BoolVar(&cliArgs.shortLinks, "short-links", false, "Render shortened link labels, stripping packages and modules.")
×
54
        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.")
×
55

×
56
        root.Flags().SortFlags = false
×
57

×
58
        return root
×
59
}
60

61
func run(args *args) error {
×
62
        if args.outDir == "" {
×
63
                return fmt.Errorf("no output path given")
×
64
        }
×
65

66
        data, err := read(args.file)
×
67
        if err != nil {
×
68
                return err
×
69
        }
×
70

71
        docs, err := document.FromJson(data)
×
72
        if err != nil {
×
73
                return err
×
74
        }
×
75

76
        rFormat, err := format.GetFormat(args.renderFormat)
×
77
        if err != nil {
×
78
                return err
×
79
        }
×
80
        if args.caseInsensitive {
×
81
                document.CaseSensitiveSystem = false
×
82
        }
×
83

NEW
84
        err = format.Render(docs, args.outDir, rFormat, args.useExports, args.shortLinks)
×
85
        if err != nil {
×
86
                return err
×
87
        }
×
88

89
        return nil
×
90
}
91

92
func read(file string) ([]byte, error) {
×
93
        if file == "" {
×
94
                return io.ReadAll(os.Stdin)
×
95
        } else {
×
96
                return os.ReadFile(file)
×
97
        }
×
98
}
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