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

mlange-42 / modo / 12775901286

14 Jan 2025 08:31PM CUT coverage: 34.058% (+0.2%) from 33.838%
12775901286

Pull #36

github

web-flow
Merge a0c741f43 into 2dc9d3121
Pull Request #36: Add Hugo export format

16 of 53 new or added lines in 7 files covered. (30.19%)

1 existing line in 1 file now uncovered.

282 of 828 relevant lines covered (34.06%)

2.1 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
        "log"
7
        "os"
8

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

15
type renderFormats struct {
16
        mdBook bool
17
        hugo   bool
18
}
19

20
func rootCommand() *cobra.Command {
×
21
        var file string
×
22
        var formats renderFormats
×
23
        var caseInsensitive bool
×
24

×
25
        root := &cobra.Command{
×
26
                Use:   "modo OUT-PATH",
×
27
                Short: "Mojo documentation generator",
×
28
                Long:  ``,
×
29
                Args:  cobra.ExactArgs(1),
×
30
                RunE: func(cmd *cobra.Command, args []string) error {
×
31
                        outDir := args[0]
×
32

×
33
                        if outDir == "" {
×
34
                                return fmt.Errorf("no output path given")
×
35
                        }
×
36

37
                        data, err := read(file)
×
38
                        if err != nil {
×
39
                                return err
×
40
                        }
×
41

42
                        docs, err := document.FromJson(data)
×
43
                        if err != nil {
×
44
                                log.Fatal(err)
×
45
                        }
×
46

47
                        rFormat := getFormat(&formats)
×
48
                        if caseInsensitive {
×
49
                                document.CaseSensitiveSystem = false
×
50
                        }
×
51

52
                        err = modo.Render(docs, outDir, rFormat)
×
53
                        if err != nil {
×
54
                                log.Fatal(err)
×
55
                        }
×
56

57
                        return nil
×
58
                },
59
        }
60

61
        root.Flags().StringVarP(&file, "input", "i", "", "File to read. Reads from STDIN if not specified.")
×
62
        root.Flags().BoolVar(&formats.mdBook, "mdbook", false, "Writes in mdBook format.")
×
NEW
63
        root.Flags().BoolVar(&formats.hugo, "hugo", false, "Writes in Hugo format.")
×
64
        root.Flags().BoolVar(&caseInsensitive, "case-insensitive", false, "Build for systems that are not case-sensitive regarding file names.\nAppends hyphen (-) to capitalized file names.")
×
65

×
NEW
66
        root.MarkFlagsMutuallyExclusive("mdbook", "hugo")
×
67

×
68
        return root
×
69
}
70

71
func read(file string) ([]byte, error) {
×
72
        if file == "" {
×
73
                return io.ReadAll(os.Stdin)
×
74
        } else {
×
75
                return os.ReadFile(file)
×
76
        }
×
77
}
78

79
func getFormat(f *renderFormats) format.Format {
×
80
        if f.mdBook {
×
81
                return format.MdBook
×
82
        }
×
NEW
83
        if f.hugo {
×
NEW
84
                return format.Hugo
×
NEW
85
        }
×
UNCOV
86
        return format.Plain
×
87
}
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