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

mlange-42 / modo / 13180866156

06 Feb 2025 02:21PM CUT coverage: 73.089% (-1.0%) from 74.08%
13180866156

push

github

web-flow
Add tests for CLI commands (#212)

36 of 54 new or added lines in 6 files covered. (66.67%)

2314 of 3166 relevant lines covered (73.09%)

40.88 hits per line

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

73.58
/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() (*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
                        start := time.Now()
1✔
40

1✔
41
                        cliArgs, err := document.ConfigFromViper(v)
1✔
42
                        if err != nil {
1✔
43
                                return err
×
44
                        }
×
45
                        if err := runClean(cliArgs); err != nil {
1✔
NEW
46
                                return err
×
NEW
47
                        }
×
48

49
                        if err := os.Chdir(cwd); err != nil {
1✔
NEW
50
                                return err
×
NEW
51
                        }
×
52

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

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

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

3✔
63
        return root, nil
3✔
64
}
65

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

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

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