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

mlange-42 / modo / 12816549311

16 Jan 2025 07:54PM CUT coverage: 34.117% (-3.0%) from 37.068%
12816549311

Pull #46

github

web-flow
Merge bad20b0e7 into cd52159d3
Pull Request #46: Fix overwritten cross-refs for multi re-export

0 of 105 new or added lines in 3 files covered. (0.0%)

450 of 1319 relevant lines covered (34.12%)

2.48 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
        "os"
7

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

13
func main() {
×
14
        if err := rootCommand().Execute(); err != nil {
×
15
                fmt.Println("Use 'modo --help' for help.")
×
16
                os.Exit(1)
×
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: "Modo -- DocGen for Mojo.",
×
35
                Long: `Modo -- DocGen for Mojo.
×
36

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

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

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

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

×
59
        return root
×
60
}
61

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

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

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

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

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

90
        return nil
×
91
}
92

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