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

mlange-42 / modo / 13182145978

06 Feb 2025 03:26PM CUT coverage: 74.117% (+1.0%) from 73.089%
13182145978

push

github

web-flow
Add test for watch mode (#213)

21 of 39 new or added lines in 6 files covered. (53.85%)

2351 of 3172 relevant lines covered (74.12%)

48.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/internal/cmd/clean.go
1
package cmd
2

3
import (
4
        "fmt"
5
        "os"
6
        "time"
7

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

14
func cleanCommand(_ chan struct{}) (*cobra.Command, error) {
3✔
15
        v := viper.New()
3✔
16
        var config string
3✔
17

3✔
18
        var cwd string
3✔
19

3✔
20
        root := &cobra.Command{
3✔
21
                Use:   "clean [PATH]",
3✔
22
                Short: "Remove Markdown and test files generated by Modo",
3✔
23
                Long: `Remove Markdown and test files generated by Modo.
3✔
24

3✔
25
Complete documentation at https://mlange-42.github.io/modo/`,
3✔
26
                Args:         cobra.MaximumNArgs(1),
3✔
27
                SilenceUsage: true,
3✔
28
                PreRunE: func(cmd *cobra.Command, args []string) error {
4✔
29
                        var err error
1✔
30
                        if err = checkConfigFile(config); err != nil {
1✔
31
                                return err
×
32
                        }
×
33
                        if cwd, err = mountProject(v, config, args); err != nil {
1✔
34
                                return err
×
35
                        }
×
36
                        return nil
1✔
37
                },
38
                RunE: func(cmd *cobra.Command, args []string) error {
1✔
39
                        defer func() {
2✔
40
                                if err := os.Chdir(cwd); err != nil {
1✔
NEW
41
                                        fmt.Println(err)
×
NEW
42
                                }
×
43
                        }()
44

45
                        start := time.Now()
1✔
46

1✔
47
                        cliArgs, err := document.ConfigFromViper(v)
1✔
48
                        if err != nil {
1✔
49
                                return err
×
50
                        }
×
51
                        if err := runClean(cliArgs); err != nil {
1✔
52
                                return err
×
53
                        }
×
54

55
                        fmt.Printf("Completed in %.1fms 🧯\n", float64(time.Since(start).Microseconds())/1000.0)
1✔
56
                        return nil
1✔
57
                },
58
        }
59

60
        root.Flags().StringVarP(&config, "config", "c", defaultConfigFile, "Config file in the working directory to use")
3✔
61

3✔
62
        root.Flags().SortFlags = false
3✔
63
        root.MarkFlagFilename("config", "yaml")
3✔
64

3✔
65
        return root, nil
3✔
66
}
67

68
func runClean(args *document.Config) error {
1✔
69
        if args.OutputDir == "" {
1✔
70
                return fmt.Errorf("no output path given")
×
71
        }
×
72

73
        formatter, err := format.GetFormatter(args.RenderFormat)
1✔
74
        if err != nil {
1✔
75
                return err
×
76
        }
×
77

78
        return formatter.Clean(args.OutputDir, args.TestOutput)
1✔
79
}
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