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

mlange-42 / modo / 12828318641

17 Jan 2025 11:37AM CUT coverage: 48.228% (+11.7%) from 36.563%
12828318641

Pull #54

github

web-flow
Merge 519b6c6c2 into 41ff6f833
Pull Request #54: More unit tests

12 of 28 new or added lines in 3 files covered. (42.86%)

108 existing lines in 3 files now uncovered.

626 of 1298 relevant lines covered (48.23%)

3.77 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
        "strings"
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
                fmt.Println("Use 'modo --help' for help.")
×
17
                os.Exit(1)
×
18
        }
×
19
}
20

21
type args struct {
22
        file            string
23
        renderFormat    string
24
        caseInsensitive bool
25
        useExports      bool
26
        shortLinks      bool
27
        outDir          string
28
        templateDirs    []string
29
}
30

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

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

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

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

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

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

×
64
        return root
×
65
}
66

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

72
        docs, err := readDocs(args.file)
×
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

NEW
85
        err = format.Render(docs, &format.Config{
×
NEW
UNCOV
86
                OutputDir:    args.outDir,
×
NEW
87
                TemplateDirs: args.templateDirs,
×
NEW
88
                RenderFormat: rFormat,
×
NEW
89
                UseExports:   args.useExports,
×
NEW
90
                ShortLinks:   args.shortLinks,
×
NEW
91
        })
×
92
        if err != nil {
×
93
                return err
×
94
        }
×
95

96
        return nil
×
97
}
98

UNCOV
99
func readDocs(file string) (*document.Docs, error) {
×
UNCOV
100
        data, err := read(file)
×
101
        if err != nil {
×
102
                return nil, err
×
103
        }
×
104

105
        if strings.HasSuffix(file, ".yaml") || strings.HasSuffix(file, ".yml") {
×
UNCOV
106
                return document.FromYaml(data)
×
107
        }
×
108

109
        return document.FromJson(data)
×
110
}
111

UNCOV
112
func read(file string) ([]byte, error) {
×
UNCOV
113
        if file == "" {
×
114
                return io.ReadAll(os.Stdin)
×
115
        } else {
×
116
                return os.ReadFile(file)
×
117
        }
×
118
}
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