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

mlange-42 / modo / 12790465070

15 Jan 2025 02:29PM CUT coverage: 34.803% (+0.7%) from 34.058%
12790465070

Pull #41

github

web-flow
Merge 38ba8e822 into 76eff0dc3
Pull Request #41: Add flag for shorter link labels

17 of 21 new or added lines in 4 files covered. (80.95%)

292 of 839 relevant lines covered (34.8%)

2.23 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
        shortLinks      bool
25
        outDir          string
26
}
27

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

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

42
        root.Flags().StringVarP(&cliArgs.file, "input", "i", "", "File to read. Reads from STDIN if not specified.")
×
43
        root.Flags().StringVarP(&cliArgs.renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
NEW
44
        root.Flags().BoolVar(&cliArgs.shortLinks, "short-links", false, "Renders shortened link labels, stripping packages and modules.")
×
45
        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.")
×
46

×
47
        root.Flags().SortFlags = false
×
48

×
49
        return root
×
50
}
51

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

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

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

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

NEW
75
        err = format.Render(docs, args.outDir, rFormat, args.shortLinks)
×
76
        if err != nil {
×
77
                return err
×
78
        }
×
79

80
        return nil
×
81
}
82

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