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

mlange-42 / modo / 13179389384

06 Feb 2025 01:02PM CUT coverage: 56.505% (-17.6%) from 74.08%
13179389384

Pull #212

github

web-flow
Merge 82bca64de into 1566231bf
Pull Request #212: Add tests for CLI commands

1772 of 3136 relevant lines covered (56.51%)

21.11 hits per line

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

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

3
import (
4
        "fmt"
5

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

12
func cleanCommand() (*cobra.Command, error) {
×
13
        v := viper.New()
×
14
        var config string
×
15

×
16
        root := &cobra.Command{
×
17
                Use:   "clean [PATH]",
×
18
                Short: "Remove Markdown and test files generated by Modo",
×
19
                Long: `Remove Markdown and test files generated by Modo.
×
20

×
21
Complete documentation at https://mlange-42.github.io/modo/`,
×
22
                Args:         cobra.MaximumNArgs(1),
×
23
                SilenceUsage: true,
×
24
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
25
                        if err := checkConfigFile(config); err != nil {
×
26
                                return err
×
27
                        }
×
28
                        if err := mountProject(v, config, args); err != nil {
×
29
                                return err
×
30
                        }
×
31
                        return nil
×
32
                },
33
                RunE: func(cmd *cobra.Command, args []string) error {
×
34
                        cliArgs, err := document.ConfigFromViper(v)
×
35
                        if err != nil {
×
36
                                return err
×
37
                        }
×
38
                        return runClean(cliArgs)
×
39
                },
40
        }
41

42
        root.Flags().StringVarP(&config, "config", "c", defaultConfigFile, "Config file in the working directory to use")
×
43

×
44
        root.Flags().SortFlags = false
×
45
        root.MarkFlagFilename("config", "yaml")
×
46

×
47
        return root, nil
×
48
}
49

50
func runClean(args *document.Config) error {
×
51
        if args.OutputDir == "" {
×
52
                return fmt.Errorf("no output path given")
×
53
        }
×
54

55
        formatter, err := format.GetFormatter(args.RenderFormat)
×
56
        if err != nil {
×
57
                return err
×
58
        }
×
59

60
        return formatter.Clean(args.OutputDir, args.TestOutput)
×
61
}
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