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

mlange-42 / modo / 12787149500

15 Jan 2025 11:15AM CUT coverage: 34.058%. Remained the same
12787149500

push

github

web-flow
Update CHANGELOG for v0.4.0 (#40)

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
/main.go
1
package main
2

3
import (
4
        "fmt"
5
        "io"
6
        "log"
7
        "os"
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
                log.Fatal(err)
×
17
        }
×
18
}
19

20
type args struct {
21
        file            string
22
        renderFormat    string
23
        caseInsensitive bool
24
        outDir          string
25
}
26

27
func rootCommand() *cobra.Command {
×
28
        var cliArgs args
×
29

×
30
        root := &cobra.Command{
×
31
                Use:   "modo OUT-PATH",
×
32
                Short: "Mojo documentation generator",
×
33
                Long:  ``,
×
34
                Args:  cobra.ExactArgs(1),
×
35
                RunE: func(cmd *cobra.Command, args []string) error {
×
36
                        cliArgs.outDir = args[0]
×
37
                        return run(&cliArgs)
×
38
                },
×
39
        }
40

41
        root.Flags().StringVarP(&cliArgs.file, "input", "i", "", "File to read. Reads from STDIN if not specified.")
×
42
        root.Flags().StringVarP(&cliArgs.renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
43
        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.")
×
44

×
45
        root.Flags().SortFlags = false
×
46

×
47
        return root
×
48
}
49

50
func run(args *args) error {
×
51
        if args.outDir == "" {
×
52
                return fmt.Errorf("no output path given")
×
53
        }
×
54

55
        data, err := read(args.file)
×
56
        if err != nil {
×
57
                return err
×
58
        }
×
59

60
        docs, err := document.FromJson(data)
×
61
        if err != nil {
×
62
                return err
×
63
        }
×
64

65
        rFormat, err := format.GetFormat(args.renderFormat)
×
66
        if err != nil {
×
67
                return err
×
68
        }
×
69
        if args.caseInsensitive {
×
70
                document.CaseSensitiveSystem = false
×
71
        }
×
72

73
        err = format.Render(docs, args.outDir, rFormat)
×
74
        if err != nil {
×
75
                return err
×
76
        }
×
77

78
        return nil
×
79
}
80

81
func read(file string) ([]byte, error) {
×
82
        if file == "" {
×
83
                return io.ReadAll(os.Stdin)
×
84
        } else {
×
85
                return os.ReadFile(file)
×
86
        }
×
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