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

charmbracelet / glow / 9862755377

09 Jul 2024 07:02PM UTC coverage: 10.105%. Remained the same
9862755377

Pull #627

github

caarlos0
ci: run govulncheck, semgrep, etc

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Pull Request #627: ci: run govulncheck, semgrep, etc

1 of 2 new or added lines in 2 files covered. (50.0%)

54 existing lines in 2 files now uncovered.

192 of 1900 relevant lines covered (10.11%)

4.61 hits per line

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

27.91
/config_cmd.go
1
package main
2

3
import (
4
        "fmt"
5
        "os"
6
        "path"
7
        "path/filepath"
8

9
        "github.com/charmbracelet/x/editor"
10
        "github.com/spf13/cobra"
11
        "github.com/spf13/viper"
12
)
13

14
const defaultConfig = `# style name or JSON path (default "auto")
15
style: "auto"
16
# mouse support (TUI-mode only)
17
mouse: false
18
# use pager to display markdown
19
pager: false
20
# word-wrap at width
21
width: 80
22
`
23

24
var configCmd = &cobra.Command{
25
        Use:     "config",
26
        Hidden:  false,
27
        Short:   "Edit the glow config file",
28
        Long:    paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))),
29
        Example: paragraph("glow config\nglow config --config path/to/config.yml"),
30
        Args:    cobra.NoArgs,
UNCOV
31
        RunE: func(*cobra.Command, []string) error {
×
UNCOV
32
                if err := ensureConfigFile(); err != nil {
×
33
                        return err
×
34
                }
×
35

36
                c, err := editor.Cmd("Glow", configFile)
×
UNCOV
37
                if err != nil {
×
38
                        return err
×
39
                }
×
40
                c.Stdin = os.Stdin
×
41
                c.Stdout = os.Stdout
×
42
                c.Stderr = os.Stderr
×
43
                if err := c.Run(); err != nil {
×
44
                        return err
×
45
                }
×
46

47
                fmt.Println("Wrote config file to:", configFile)
×
UNCOV
48
                return nil
×
49
        },
50
}
51

52
func ensureConfigFile() error {
1✔
53
        if configFile == "" {
1✔
UNCOV
54
                configFile = viper.GetViper().ConfigFileUsed()
×
UNCOV
55
                if err := os.MkdirAll(filepath.Dir(configFile), 0o755); err != nil {
×
56
                        return fmt.Errorf("could not write configuration file: %w", err)
×
57
                }
×
58
        }
59

60
        if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" {
1✔
UNCOV
61
                return fmt.Errorf("'%s' is not a supported configuration type: use '%s' or '%s'", ext, ".yaml", ".yml")
×
UNCOV
62
        }
×
63

64
        if _, err := os.Stat(configFile); os.IsNotExist(err) {
2✔
65
                // File doesn't exist yet, create all necessary directories and
1✔
66
                // write the default config file
1✔
67
                if err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {
1✔
UNCOV
68
                        return err
×
UNCOV
69
                }
×
70

71
                f, err := os.Create(configFile)
1✔
72
                if err != nil {
1✔
UNCOV
73
                        return err
×
UNCOV
74
                }
×
75
                defer func() { _ = f.Close() }()
2✔
76

77
                if _, err := f.WriteString(defaultConfig); err != nil {
1✔
UNCOV
78
                        return err
×
UNCOV
79
                }
×
80
        } else if err != nil { // some other error occurred
×
81
                return err
×
82
        }
×
83
        return nil
1✔
84
}
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