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

mlange-42 / modo / 12818254039

16 Jan 2025 09:52PM CUT coverage: 35.271% (-1.1%) from 36.349%
12818254039

Pull #48

github

web-flow
Merge 07b6c4ea0 into 6785e722a
Pull Request #48: Custom template overwrites

6 of 45 new or added lines in 5 files covered. (13.33%)

443 of 1256 relevant lines covered (35.27%)

2.62 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
        templateDirs    []string
28
}
29

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

×
33
        root := &cobra.Command{
×
34
                Use:   "modo OUT-PATH",
×
35
                Short: "Modo -- DocGen for Mojo.",
×
36
                Long: `Modo -- DocGen for Mojo.
×
37

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

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

52
        root.Flags().StringVarP(&cliArgs.file, "input", "i", "", "'mojo doc' JSON file to process. Reads from STDIN if not specified.")
×
53
        root.Flags().StringVarP(&cliArgs.renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
54
        root.Flags().BoolVarP(&cliArgs.useExports, "exports", "e", false, "Process according to 'Exports:' sections in packages.")
×
55
        root.Flags().BoolVar(&cliArgs.shortLinks, "short-links", false, "Render shortened link labels, stripping packages and modules.")
×
56
        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.")
×
NEW
57
        root.Flags().StringSliceVarP(&cliArgs.templateDirs, "templates", "t", []string{}, "Optional directories with templates for (partial) overwrite.\nSee folder assets/templates in the repository.")
×
58

×
59
        root.Flags().SortFlags = false
×
NEW
60
        root.MarkFlagFilename("input", "json")
×
NEW
61
        root.MarkFlagDirname("templates")
×
62

×
63
        return root
×
64
}
65

66
func run(args *args) error {
×
67
        if args.outDir == "" {
×
68
                return fmt.Errorf("no output path given")
×
69
        }
×
70

71
        data, err := read(args.file)
×
72
        if err != nil {
×
73
                return err
×
74
        }
×
75

76
        docs, err := document.FromJson(data)
×
77
        if err != nil {
×
78
                return err
×
79
        }
×
80

81
        rFormat, err := format.GetFormat(args.renderFormat)
×
82
        if err != nil {
×
83
                return err
×
84
        }
×
85
        if args.caseInsensitive {
×
86
                document.CaseSensitiveSystem = false
×
87
        }
×
88

NEW
89
        err = format.Render(docs, args.outDir, args.templateDirs, rFormat, args.useExports, args.shortLinks)
×
90
        if err != nil {
×
91
                return err
×
92
        }
×
93

94
        return nil
×
95
}
96

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