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

mlange-42 / modo / 12737935283

12 Jan 2025 11:14PM CUT coverage: 24.557%. Remained the same
12737935283

Pull #26

github

web-flow
Merge fdc77f32e into ee3165c19
Pull Request #26: Add CI tests on stable and nightly

97 of 395 relevant lines covered (24.56%)

1.28 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
}
18

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

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

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

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

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

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

51
                        err = modo.RenderPackage(docs.Decl, outDir, rFormat, true)
×
52
                        if err != nil {
×
53
                                log.Fatal(err)
×
54
                        }
×
55

56
                        return nil
×
57
                },
58
        }
59

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

×
64
        root.MarkFlagsMutuallyExclusive("mdbook")
×
65

×
66
        return root
×
67
}
68

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

77
func getFormat(f *renderFormats) format.Format {
×
78
        if f.mdBook {
×
79
                return format.MdBook
×
80
        }
×
81
        return format.Plain
×
82
}
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