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

mlange-42 / modo / 12858520582

20 Jan 2025 12:21AM CUT coverage: 56.633% (-0.8%) from 57.418%
12858520582

Pull #73

github

web-flow
Merge 76145dc26 into ef546a39d
Pull Request #73: Fix cross-refs to package and module aliases

8 of 34 new or added lines in 7 files covered. (23.53%)

2 existing lines in 2 files now uncovered.

841 of 1485 relevant lines covered (56.63%)

8.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
        "os"
7
        "strings"
8
        "time"
9

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

15
func main() {
×
16
        start := time.Now()
×
17
        if err := rootCommand().Execute(); err != nil {
×
18
                fmt.Println("Use 'modo --help' for help.")
×
19
                os.Exit(1)
×
20
        }
×
21
        fmt.Printf("Completed in %.1fms 🧯\n", float64(time.Since(start).Microseconds())/1000.0)
×
22
}
23

24
func rootCommand() *cobra.Command {
×
25
        var cliArgs document.Config
×
26
        var renderFormat string
×
27

×
28
        root := &cobra.Command{
×
29
                Use:   "modo OUT-PATH",
×
30
                Short: "Modo -- DocGen for Mojo.",
×
31
                Long: `Modo -- DocGen for Mojo.
×
32

×
33
Modo generates Markdown for static site generators (SSGs) from 'mojo doc' JSON output.`,
×
34
                Example: `  modo docs -i docs.json        # from a file
×
35
  mojo doc ./src | modo docs    # from 'mojo doc'`,
×
36
                Args:         cobra.ExactArgs(1),
×
37
                SilenceUsage: true,
×
38
                RunE: func(cmd *cobra.Command, args []string) error {
×
39
                        cliArgs.OutputDir = args[0]
×
40
                        return run(&cliArgs, renderFormat)
×
41
                },
×
42
        }
43

44
        root.Flags().StringVarP(&cliArgs.InputFile, "input", "i", "", "'mojo doc' JSON file to process. Reads from STDIN if not specified.")
×
45
        root.Flags().StringVarP(&renderFormat, "format", "f", "plain", "Output format. One of (plain|mdbook|hugo).")
×
46
        root.Flags().BoolVarP(&cliArgs.UseExports, "exports", "e", false, "Process according to 'Exports:' sections in packages.")
×
47
        root.Flags().BoolVar(&cliArgs.ShortLinks, "short-links", false, "Render shortened link labels, stripping packages and modules.")
×
48
        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.")
×
49
        root.Flags().BoolVar(&cliArgs.Strict, "strict", false, "Strict mode. Errors instead of warnings.")
×
50
        root.Flags().BoolVar(&cliArgs.DryRun, "dry-run", false, "Dry-run without any file output.")
×
51
        root.Flags().StringSliceVarP(&cliArgs.TemplateDirs, "templates", "t", []string{}, "Optional directories with templates for (partial) overwrite.\nSee folder assets/templates in the repository.")
×
52

×
53
        root.Flags().SortFlags = false
×
54
        root.MarkFlagFilename("input", "json")
×
55
        root.MarkFlagDirname("templates")
×
56

×
57
        return root
×
58
}
59

60
func run(args *document.Config, renderFormat string) error {
×
61
        if args.OutputDir == "" {
×
62
                return fmt.Errorf("no output path given")
×
63
        }
×
64

65
        docs, err := readDocs(args.InputFile)
×
66
        if err != nil {
×
67
                return err
×
68
        }
×
69

70
        rFormat, err := format.GetFormat(renderFormat)
×
71
        if err != nil {
×
72
                return err
×
73
        }
×
74
        formatter := format.GetFormatter(rFormat)
×
75
        err = formatter.Render(docs, args)
×
76
        if err != nil {
×
77
                return err
×
78
        }
×
79

80
        return nil
×
81
}
82

83
func readDocs(file string) (*document.Docs, error) {
×
84
        data, err := read(file)
×
85
        if err != nil {
×
86
                return nil, err
×
87
        }
×
88

89
        if strings.HasSuffix(file, ".yaml") || strings.HasSuffix(file, ".yml") {
×
90
                return document.FromYaml(data)
×
91
        }
×
92

93
        return document.FromJson(data)
×
94
}
95

96
func read(file string) ([]byte, error) {
×
97
        if file == "" {
×
98
                return io.ReadAll(os.Stdin)
×
99
        } else {
×
100
                return os.ReadFile(file)
×
101
        }
×
102
}
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