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

mlange-42 / modo / 12777356798

14 Jan 2025 10:15PM CUT coverage: 33.894%. Remained the same
12777356798

Pull #38

github

web-flow
Merge 3224f39a6 into 3ddfea5df
Pull Request #38: Use actual element kind for path processing

0 of 1 new or added line in 1 file covered. (0.0%)

282 of 832 relevant lines covered (33.89%)

2.09 hits per line

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

0.0
/cmd/modo/root.go
1
package main
2

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

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

14
func rootCommand() *cobra.Command {
×
15
        var file string
×
16
        var renderFormat string
×
17
        var caseInsensitive bool
×
18

×
19
        root := &cobra.Command{
×
20
                Use:   "modo OUT-PATH",
×
21
                Short: "Mojo documentation generator",
×
22
                Long:  ``,
×
23
                Args:  cobra.ExactArgs(1),
×
24
                RunE: func(cmd *cobra.Command, args []string) error {
×
25
                        outDir := args[0]
×
26

×
27
                        if outDir == "" {
×
28
                                return fmt.Errorf("no output path given")
×
29
                        }
×
30

31
                        data, err := read(file)
×
32
                        if err != nil {
×
33
                                return err
×
34
                        }
×
35

36
                        docs, err := document.FromJson(data)
×
37
                        if err != nil {
×
38
                                return err
×
39
                        }
×
40

41
                        rFormat, err := getFormat(renderFormat)
×
42
                        if err != nil {
×
43
                                return err
×
44
                        }
×
45
                        if caseInsensitive {
×
46
                                document.CaseSensitiveSystem = false
×
47
                        }
×
48

49
                        err = modo.Render(docs, outDir, rFormat)
×
50
                        if err != nil {
×
51
                                return err
×
52
                        }
×
53

54
                        return nil
×
55
                },
56
        }
57

58
        root.Flags().StringVarP(&file, "input", "i", "", "File to read. Reads from STDIN if not specified.")
×
59
        root.Flags().StringVarP(&renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
60
        root.Flags().BoolVar(&caseInsensitive, "case-insensitive", false, "Build for systems that are not case-sensitive regarding file names.\nAppends hyphen (-) to capitalized file names.")
×
61

×
62
        root.Flags().SortFlags = false
×
63

×
64
        return root
×
65
}
66

67
func read(file string) ([]byte, error) {
×
68
        if file == "" {
×
69
                return io.ReadAll(os.Stdin)
×
70
        } else {
×
71
                return os.ReadFile(file)
×
72
        }
×
73
}
74

75
func getFormat(f string) (format.Format, error) {
×
76
        fm, ok := format.GetFormat(f)
×
77
        if !ok {
×
78
                return format.Plain, fmt.Errorf("unknown format '%s'. See flag --format", f)
×
79
        }
×
80
        return fm, nil
×
81
}
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